From e07e13fd35be4e91595465dbfc00edcddaf09d44 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 12 Oct 2019 15:10:39 +0000 Subject: [PATCH] Add hexdump for kernel --- kernel/dump.asm | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 kernel/dump.asm diff --git a/kernel/dump.asm b/kernel/dump.asm new file mode 100644 index 0000000..b01da68 --- /dev/null +++ b/kernel/dump.asm @@ -0,0 +1,85 @@ +; print a word +; in: ax +print16: + xchg ah,al + call print8 + xchg ah,al + +; print a byte +; in: al +print8: + push ax ; avoid destroying ah + push bx + xor bx, bx + aam 16 ; high nibble moved into ah, low nibble into al + add ax, 0x3030 + push ax + xchg al, ah + call .nib + pop ax + call .nib + pop bx + pop ax + ret +.nib: + cmp al, 0x3a + jl .out + add al, 0x07 +.out: + mov dl, al + call console_output + ret + +dump: + push ax + push cx + push dx + push bx + mov dl, 0x0A + call console_output + mov dl, 0x0D + call console_output + mov cx, 4 +.loop_line: + push cx + push bx + mov ax, bx + call print16 + mov dl, ':' + call console_output + mov dl, ' ' + call console_output + mov cx, 0x8 +.loop_bin: + mov ax, [bx] + xchg al, ah + inc bx + inc bx + call print16 + mov dl, ' ' + call console_output + loop .loop_bin + pop bx + mov cx, 0x10 +.loop_ascii: + mov dl, '.' + cmp byte [bx], 0x20 + jc .print + cmp byte [bx], 0x80 + jnc .print + mov dl, [bx] +.print: + inc bx + call console_output + loop .loop_ascii + pop cx + mov dl, 0x0A + call console_output + mov dl, 0x0D + call console_output + loop .loop_line + pop bx + pop dx + pop cx + pop ax + ret