0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

各種OSアセンブリでプロセス終了

Last updated at Posted at 2023-08-20

CP/M

dev.bat
@echo off
path %path%;C:\etc\z88dk\bin
path %path%;C:\etc\cpm32_04
prompt $e[33m$p$g$e[m
cmd
hello.asm
;z80asm -l -b -ohello.com hello.asm
;cpm hello

	org	$0100

	ld	de, msg
	ld	c, $09
	call	5
	jp	0

msg:	db	"hello, world",$0d,$0a,"$"
  • 出力例
C:\Projects\CP_M>z80asm -l -b -ohello.com hello.asm

C:\Projects\CP_M>cpm hello
hello, world

MS-DOS

dev.bat
@echo off
path %path%;C:\masm32\bin
path %path%;C:\etc\msdos\binary\v30_x64
prompt $e[33m$p$g$e[m
cmd
ext16.asm
comment *
ml /c /Fl ext16.asm
link16 /t ext16;
msdos ext16
echo %errorlevel%
*
.model tiny
.code
	org	0100h
start:
	mov	al, 42
	mov	ah, 4ch
	int	21h

end start
  • 出力例
C:\Projects\MASM32>ml /c /Fl ext16.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: ext16.asm

C:\Projects\MASM32>link16 /t ext16;

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

LINK : warning L4045: name of output file is 'ext16.com'

C:\Projects\MASM32>msdos ext16

C:\Projects\MASM32>echo %errorlevel%
42

サンプル

hello
hello.asm
comment *
ml /c /Fl hello.asm
link16 /t hello;
*
.model tiny
.code
	org	0100h
start:
	mov	dx, offset msg
	mov	ah, 09h
	int	21h
	mov	ax, 4c00h
	int	21h

msg	db	'hello, world',0dh, 0ah,'$'
end start

Windows (x86)

Visual Studio 2022

dev32.bat
@echo off
path %path%;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x86
set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x86
prompt $e[33m$p$g$e[m
cmd
ext32.asm
comment *
ml /c /Fl /Sa ext32.asm
link /subsystem:console ext32
echo %errorlevel%
*
includelib kernel32

.model flat

ExitProcess proto stdcall :dword

.code
start proc c
	invoke	ExitProcess, 42
start endp

end start
  • 出力例
C:\Projects\msvc>ml /c /Fl /Sa ext32.asm
Microsoft (R) Macro Assembler Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: ext32.asm

C:\Projects\msvc>link /subsystem:console ext32
Microsoft (R) Incremental Linker Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\Projects\msvc>ext32

C:\Projects\msvc>echo %errorlevel%
42

サンプル

hello32
hello32.asm
comment *
ml /c /Fl /Sa hello32.asm
link /subsystem:console hello32
*
includelib kernel32

.model flat

NULL equ 0
STD_OUTPUT_HANDLE equ -11

ExitProcess proto stdcall :dword
GetStdHandle proto stdcall :dword
WriteConsoleA proto stdcall :dword,:dword,:dword,:dword,:dword

.const
msg	db	'hello, world',0dh,0ah
len	equ	$ - msg

.data?
hOut	dd	?

.code
start proc c
	invoke	GetStdHandle, STD_OUTPUT_HANDLE
	mov	hOut, eax
	invoke	WriteConsoleA, hOut, addr msg, len, NULL, NULL
	invoke	ExitProcess, 0
start endp

end start

Windows (x64)

Visual Studio 2022

dev64.bat
@echo off
path %path%;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64
set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64
prompt $e[33m$p$g$e[m
cmd
ext64.asm
comment *
ml64 /c /Fl ext64.asm
link /subsystem:console /entry:start ext64
echo %errorlevel%
*
includelib kernel32

extern ExitProcess :proc

.code
start proc
	sub	rsp, 28h
	mov	ecx, 42
	call	ExitProcess
start endp

end
  • 出力例
C:\Projects\msvc>ml64 /c /Fl ext64.asm
Microsoft (R) Macro Assembler (x64) Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: ext64.asm

C:\Projects\msvc>link /subsystem:console /entry:start ext64
Microsoft (R) Incremental Linker Version 14.37.32822.0
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\Projects\msvc>ext64

C:\Projects\msvc>echo %errorlevel%
42

サンプル

hello64
hello64.asm
comment *
ml64 /c /Fl hello64.asm
link /subsystem:console /entry:start hello64
*
includelib kernel32

NULL equ 0
STD_OUTPUT_HANDLE equ -11

extern ExitProcess :proc
extern GetStdHandle :proc
extern WriteConsoleA :proc

.const
msg	db	'hello, world',0dh,0ah
len	equ	$ - msg

.data?
hOut	dq	?

.code
start proc
	sub	rsp, 28h
	mov	ecx, STD_OUTPUT_HANDLE
	call	GetStdHandle
	mov	hOut, rax
	mov	qword ptr [rsp+20h], NULL
	mov	r9d, NULL
	mov	r8d, len
	mov	rdx, offset msg
	mov	rcx, hOut
	call	WriteConsoleA
	mov	ecx, 0
	call	ExitProcess
start endp

end

Linux (x86)

ext32.s
/*
Assembly(gcc,x64,Linux)
-m32 -nostdlib

as --32 -o ext32.o ext32.s
ld -m elf_i386 -s -o ext32 ext32.o
./ext32
echo $?
*/
.intel_syntax noprefix
.text
.global _start
_start:
	mov	ebx, 42
	mov	eax, 1
	int	0x80
  • 出力例
sakura@cloud-shell% vi ext32.s
sakura@cloud-shell% as --32 -o ext32.o ext32.s
sakura@cloud-shell% ld -m elf_i386 -s -o ext32 ext32.o
sakura@cloud-shell% ls
README-cloud-shell.txt  ext32*  ext32.o  ext32.s
sakura@cloud-shell% ./ext32
sakura@cloud-shell% echo $?
42

NASM
ext32.s
; Assembler 32bit (nasm 2.14)
section .const
msg	db	'hello, world',0ah
len	equ	$ - msg

section .text
global _start
_start:
	mov	edx, len
	mov	ecx, msg
	mov	ebx, 1
	mov	eax, 04h
	int	80h

	mov	ebx, 0
	mov	eax, 01h
	int	80h

https://ideone.com/wLNGtV

サンプル

hello32
hello32.s
/*
as --32 -o hello32.o hello32.s
ld -m elf_i386 -s -o hello32 hello32.o
*/
.intel_syntax noprefix

.data
msg:	.ascii	"hello, world\n"
len = . - msg

.text
.global _start
_start:
	mov	edx, len
	lea	ecx, msg
	mov	ebx, 1
	mov	eax, 4
	int	0x80
	mov	ebx, 0
	mov	eax, 1
	int	0x80

Linux (x64)

ext64.s
/*
Assembly(as,x64,Linux)

as -o ext64.o ext64.s
ld -o ext64 ext64.o
./ext64
echo $?
*/
.intel_syntax noprefix
.text
.global _start
_start:
	mov	edi, 42
	mov	eax, 60
	syscall
  • 出力例
sakura@cloud-shell% vi ext64.s
sakura@cloud-shell% as -o ext64.o ext64.s
sakura@cloud-shell% ld -o ext64 ext64.o
sakura@cloud-shell% ls
README-cloud-shell.txt  ext64*  ext64.o  ext64.s
sakura@cloud-shell% ./ext64
sakura@cloud-shell% echo $?
42

サンプル

hello64
hello64.s
/*
Assembly(as,x64,Linux)

as -o hello64.o hello64.s
ld -o hello64 hello64.o
*/
.intel_syntax noprefix

.data
msg:	.ascii	"hello, world\n"
len = . - msg

.text
.global _start
_start:
	mov	edx, len
	lea	rsi, msg
	mov	edi, 1
	mov	eax, 1
	syscall
	mov	edi, 0
	mov	eax, 60
	syscall
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?