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?

axxで80386のハンドリング 'Hello World'

Last updated at Posted at 2025-09-18

axxで80386のハンドリングをします。Hello Worldです。

パターンファイル

386.axx
MOV EAX,!d	:: 0xb8,d,d>>8,d>>16,d>>24
MOV EBX,!d      :: 0xbb,d,d>>8,d>>16,d>>24
MOV ECX,!d      :: 0xb9,d,d>>8,d>>16,d>>24
MOV EDX,!d      :: 0xbA,d,d>>8,d>>16,d>>24
INT !d		:: 0xcd,d
XOR EBX,EBX	:: 0x31,0xdb
DB  !d		:: d


アセンブリソース

hw386.s
; hello_freebsd_syscall.asm
; i386 FreeBSD, syscalls directly (int 0x80)

section .text
    .export _start

_start:
    ; write(1, msg, len)
    mov     eax,4 ; SYS write
    mov     ebx,1 ; fd=1
    mov     ecx,msg
    mov     edx,len
    int     0x80

    ; exit(0)
    mov     eax,1 ; SYS exit
    xor     ebx,ebx
    int     0x80


msg:
	.ascii "Hello, world"
	db 0x0A
len:	.equ $$ - msg


アセンブル

% axx.py 386.axx hw386.s -o hw386.bin
0000000000000000 hw386.s 1 ; hello_freebsd_syscall.asm 
0000000000000000 hw386.s 2 ; i386 FreeBSD, syscalls directly (int 0x80) 
0000000000000000 hw386.s 3  
0000000000000000 hw386.s 4 section .text 
0000000000000000 hw386.s 5     .export _start 
0000000000000000 hw386.s 6  
0000000000000000 hw386.s 7 _start: 
0000000000000000 hw386.s 8     ; write(1, msg, len) 
0000000000000000 hw386.s 9     mov     eax,4 ; SYS write  0xb8 0x04 0x00 0x00 0x00
0000000000000005 hw386.s 10     mov     ebx,1 ; fd=1  0xbb 0x01 0x00 0x00 0x00
000000000000000a hw386.s 11     mov     ecx,msg  0xb9 0x1f 0x00 0x00 0x00
000000000000000f hw386.s 12     mov     edx,len  0xba 0x0d 0x00 0x00 0x00
0000000000000014 hw386.s 13     int     0x80  0xcd 0x80
0000000000000016 hw386.s 14  
0000000000000016 hw386.s 15     ; exit(0) 
0000000000000016 hw386.s 16     mov     eax,1 ; SYS exit  0xb8 0x01 0x00 0x00 0x00
000000000000001b hw386.s 17     xor     ebx,ebx  0x31 0xdb
000000000000001d hw386.s 18     int     0x80  0xcd 0x80
000000000000001f hw386.s 19  
000000000000001f hw386.s 20  
000000000000001f hw386.s 21 msg: 
000000000000001f hw386.s 22 	.ascii "Hello, world"  0x48 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x6f 0x72 0x6c 0x64
000000000000002b hw386.s 23 	db 0x0A  0x0a
000000000000002c hw386.s 24 len:	.equ $$ - msg 
000000000000002c hw386.s 25  

ダンプ

% hexdump -C hw386.bin
00000000  b8 04 00 00 00 bb 01 00  00 00 b9 1f 00 00 00 ba  |................|
00000010  0d 00 00 00 cd 80 b8 01  00 00 00 31 db cd 80 48  |...........1...H|
00000020  65 6c 6c 6f 2c 20 77 6f  72 6c 64 0a              |ello, world.|
0000002c
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?