diff --git a/main.asm b/main.asm index cc81c2a..0fbc67f 100644 --- a/main.asm +++ b/main.asm @@ -5,8 +5,15 @@ section KERNEL follows=BOOTSECTOR vstart=1000h main: - mov bx, 65535 - call print_uint + mov bx, 156 + call print_sint + + ;mov ax, -20 + ;mov dx, 0x0003 + ;mov cx, 10 + ;idiv cx + ;mov bx, ax + ;call print_uint jmp $ ; Halt diff --git a/main.bin b/main.bin index d02d440..319edc2 100644 Binary files a/main.bin and b/main.bin differ diff --git a/print_util.asm b/print_util.asm index b86f3ed..a6c445f 100644 --- a/print_util.asm +++ b/print_util.asm @@ -1,3 +1,19 @@ +%macro print_ch 1 + push ax + mov al, %1 + mov ah, 0x0e + int 0x10 + pop ax +%endmacro + +%macro cls 0 + mov ax, 0x0600 ; AH=06 Scroll screen, AL=0 Clear screen + mov bh, 0x0F ; black bg, white fg + mov cx, 0x0000 ; x1=y1=0 + mov dx, 0x5019 ; 89x25 + int 0x10 ; Graphics services +%endmacro + print: pusha @@ -128,7 +144,7 @@ print_uint: .loop: mov cx, 10 - mov dx, 0 ; IMPORTANT: Division will not work unless the remainder register is set to 0 beforehand + mov dx, 0 ; IMPORTANT: Division will not work unless the higher register is in a usable length div cx ; Divide ax by cx (10), -> ax, rem -> dx add dx, 0x30 ; Add ascii '0' @@ -151,21 +167,21 @@ print_uint: popa ret + -_print_dec_buff: resb 6 - -%macro print_ch 1 - push ax - mov al, [%1] - mov ah, 0x0e - int 0x10 - pop ax -%endmacro - -%macro cls 0 - mov ax, 0x0600 ; AH=06 Scroll screen, AL=0 Clear screen - mov bh, 0x0F ; black bg, white fg - mov cx, 0x0000 ; x1=y1=0 - mov dx, 0x5019 ; 89x25 - int 0x10 ; Graphics services -%endmacro \ No newline at end of file +print_sint: + pusha + + ; Old (non-working method) used a copy of above with idiv. I think this way is smarter + + test bx, 0x8000 ; Check sign-bit + jz .positive + + print_ch '-' + neg bx + + .positive: + call print_uint + + popa + ret \ No newline at end of file