;INT 1H SINGLE STEPPING DEMO BY MBR_TSR
;This will be in future Versions of my Cone-Head OS
;int F9 = When Single Step mode is on Calls this int EVERY CPU instruction
;int F9 = Called by int 1 Single Step Mode DS:SI=current instruction
Org 0x0100
push cs
push cs
pop ds
pop es
mov si, Msg
call Show
mov dx, MyInt1
mov al, 1
call SetV
mov dx, IntF9 ;Calls this int every CPU instruction
mov al, 0xF9
call SetV
mov byte [cs:Int1Status], 1
int 1 ;call once to start
;Few Sample Runs...
;Some Stuff to See as CPU Instructions
mov ah, 0x0E
mov al, 0x03
int 0x10
nop
nop
nop
mov ah, 0
mov ah, 1
mov ah, 2
mov ah, 3
mov ah, 0x4c ;WE ARE DONE!
int 0x21
SetV:
pusha
push ds
push es
cli
xor bx, bx
mov es, bx
mov bl, 4
mul bl
mov bx, ax
mov word [es:bx], dx
add bx, 2
mov word [es:bx], ds
sti
pop es
pop ds
popa
ret
MyInt1:
pop word [cs:SSOff]
pop word [cs:SSSeg]
push word [cs:SSSeg]
push word [cs:SSOff]
push bp
mov bp, sp
push ax
push ds
push cs
pop ds
mov al, byte [cs:Int1Status]
cmp al, 1
jne Not1Honey
or WORD [bp + 6], 0100h
mov al, 3
mov byte [cs:Int1Status], al
jmp NoneBaby
Not1Honey:
mov al, byte [cs:Int1Status]
cmp al, 0
jne Routine
and WORD [bp + 6], 0feffh
jmp NoneBaby
Routine:
push ds
push si
mov si, word [cs:SSOff]
mov ds, word [cs:SSSeg]
int 0xF9
pop si
pop ds
NoneBaby:
pop ds
pop ax
pop bp
iret
;Dump ds:si as hex call with cx=count
DumpHex:
push ax
push bx
push cx
push si
Dumper:
lodsb
push cx
MOV CL,10h
MOV AH,0
DIV CL
ADD AL,30h
ADD AH,30h
CMP AL,'9'
JBE zCA4B
ADD AL,7
zCA4B:
CMP AH,'9'
JBE zCA5B
ADD AH,7
zCA5B:
mov CX, AX
mov al, CL
mov ah, 0eh
mov bh, 0
mov bl, 1
int 10h
mov al,CH
mov ah, 0eh
mov bh, 0
int 10h
mov ah, 0x0e
mov al, ' '
mov bx, 0x000f
int 0x10
pop cx
loop Dumper
pop si
pop cx
pop bx
pop ax
ret
;Called by Int 1h Every Instruction
;DS:SI=CS:IP
IntF9:
mov cx, 8 ;How many Bytes to Show
call DumpHex
call PrintCRLF
iret
PrintCRLF:
mov ah, 0x0E
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10
ret
Show:
push ax
push bx
push si
Show1:
lodsb
cmp al, 0
je Okay
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
int 0x10
jmp Show1
Okay:
pop si
pop bx
pop ax
ret
Msg db "Int1 Single Step Demo Dump CS:IP as Hex", 13,10, 0
Int1Status db 0 ;Int 1 Single Step 0=OFF 1=ON
SSSeg dw 0x0000
SSOff dw 0x0000
;Thats All!