debug: Add stub for instruction decoding

This commit is contained in:
Nero 2020-05-19 18:26:22 +02:00
parent a31e574b3a
commit e60e49735c
7 changed files with 49 additions and 5 deletions

9
debug/asm.asm Normal file
View File

@ -0,0 +1,9 @@
; Prints instruction at ES:BX in human-readable form
disasm: call print_esbx
call space
mov si, instr.db
call putcs
call crlf
ret

View File

@ -28,7 +28,20 @@ crlf: mov al, 0x0A
mov al, 0x0D mov al, 0x0D
jmp putc jmp putc
print16: print_dl:
mov cl, 4
; repeat 2 times
call .c
.c: mov al, dl
shl dx, cl
shr al, cl
add al, 0x30
cmp al, 0x3a
jl putc
add al, 7
jmp putc
print_dx:
mov cl, 4 mov cl, 4
; this double-call is essentially a 4 times repeating loop ; this double-call is essentially a 4 times repeating loop
call .c1 call .c1
@ -48,6 +61,19 @@ print16:
add al, 7 add al, 7
jmp putc jmp putc
print_esbx:
push cx
push dx
mov dx, es
call print_dx
mov al, ':'
call putc
mov dx, bx
call print_dx
pop dx
pop cx
ret
; Read character ; Read character
getc: xor ax, ax getc: xor ax, ax
int 0x16 int 0x16

View File

@ -52,7 +52,7 @@ printreg:
mov al, '=' mov al, '='
call putc call putc
pop dx pop dx
call print16 call print_dx
call space call space
ret ret
@ -60,7 +60,7 @@ printreg:
edit_word: edit_word:
push bx push bx
mov dx, [es:bx] mov dx, [es:bx]
call print16 call print_dx
mov al, '.' mov al, '.'
call putc call putc
mov byte [inmin], 4 mov byte [inmin], 4

View File

@ -8,3 +8,6 @@ fnames: ; control flags
db "++++ODIT" db "++++ODIT"
; status flags ; status flags
db "SZ+A+P+C" db "SZ+A+P+C"
instr:
.db: db "DB", 0

View File

@ -40,6 +40,11 @@ int3entry:
mov sp, stack mov sp, stack
call crlf call crlf
call printregs call printregs
push es
mov es, [reg_cs]
mov bx, [reg_ip]
call disasm
pop es
loop: ; show prompt loop: ; show prompt
mov al, '-' mov al, '-'

View File

@ -14,12 +14,12 @@ cmd_h: call eat_whitespace
push dx push dx
add dx, bx add dx, bx
call print16 call print_dx
call space call space
pop dx pop dx
sub dx, bx sub dx, bx
call print16 call print_dx
jmp crlf jmp crlf
.err: mov di, eat_hex_word.emsg .err: mov di, eat_hex_word.emsg

View File

@ -81,6 +81,7 @@ cerr: mov al, '?'
%include "debug/edit.asm" %include "debug/edit.asm"
%include "debug/run.asm" %include "debug/run.asm"
%include "debug/util.asm" %include "debug/util.asm"
%include "debug/asm.asm"
align 512 align 512