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?

INT命令を使わずにINT 21hを呼ぶ

Posted at

目的

前回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 far0x21の処理へ跳ぶ。

8086(V30)実機での動作確認

Hello, INT 21h!が2回表示された。
a656209c93ec78.jpg

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?