目的
前回INT
命令を読んだ際にスタックに積まれる値を調べる実験をしました。
8086:jmp/call/intによるSPとスタックの変化
今回はINT
命令使わずにINT0x21
を呼び出してみる実験を行います。
検証
nasm -f bin -o test.com test.asm
test.asm
org 0x100
start:
mov dx, msg
mov ah, 0x09
int 0x21
; intを使わずIVTを呼び出す
pushf ; FLAGS
push cs ; CS
push after_int
push ds
xor ax, ax
mov ds, ax
mov bx, [0x84] ; IP
mov cx, [0x86] ; CS
pop ds
; CS:IP をメモリに書く
mov [cs_ip_ptr], bx
mov [cs_ip_ptr+2], cx
mov dx, msg
mov ah, 0x09
jmp far [cs_ip_ptr]
after_int:
mov ah, 0x4C
xor al, al
int 0x21
msg:
db 'Hello, INT 21h!', 0Dh, 0Ah, '$'
cs_ip_ptr:
dw 0,0
処理の流れ
スタックにフラグレジスタ、CS、返りアドレスを積む。
IVT
から割り込み番号0x21
のCS、IPを取得する。
jmp far
で0x21
の処理へ跳ぶ。