rdos/debug/asm.asm

96 lines
1.3 KiB
NASM

; Prints instruction at DS:SI in human-readable form
disasm: lodsb
mov bx, opcodes
jmp .scan
.next: add bx, 8
.scan: push ax
and al, [cs:bx]
cmp al, [cs:bx+1]
pop ax
jne .next
push si
push ax
mov si, [cs:bx+2]
call putcs
pop ax
pop si
cmp word [cs:bx+4], 0
je .ret
push ax
call space
pop ax
push ax
call [cs:bx+4]
pop ax
cmp word [cs:bx+6], 0
je .ret
push ax
call print_sep
pop ax
jmp [cs:bx+6]
.ret: ret
opcodes:
; word 1: H=opcode value after AND L
; word 2: ptr to memonic
; word 3: procedure to print first operand
; word 4: procedure to print second operand
dw 0x50F8, mnem.push, operand.inr16, 0
dw 0x58F8, mnem.pop, operand.inr16, 0
dw 0xB0F8, mnem.mov, operand.inr8, 0
dw 0xB8F8, mnem.mov, operand.inr16, operand.imm16
dw 0xA4FF, mnem.movsb, 0, 0
dw 0xA5FF, mnem.movsw, 0, 0
dw 0x0000, mnem.db, operand.self, 0
print_sep:
mov al, ','
call putc
jmp space
print_r8:
push di
mov di, bnames
call print_r
pop di
ret
print_r16:
push di
mov di, rnames
call print_r
pop di
ret
print_r:
push bx
mov bl, al
xor bh, bh
add bx, bx
mov bx, [cs:bx+di]
mov al, bl
call putc
mov al, bh
call putc
pop bx
ret
operand:
.inr8: and al, 7
jmp print_r8
.inr16: and al, 7
jmp print_r16
.self: mov dl, al
jmp print_dl
.imm8: mov dl, [si]
jmp print_dl
.imm16: mov dx, [si]
jmp print_dx