From b42a2bda0c2d3de1bbbc13f93ac71e34d68791bb Mon Sep 17 00:00:00 2001 From: maelstrom Date: Wed, 24 Jul 2024 22:51:08 +0300 Subject: [PATCH] Signed int print --- main.asm | 11 +++++++++-- main.bin | Bin 730 -> 752 bytes print_util.asm | 52 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 20 deletions(-) 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 d02d440d4e8fe50d20bfcf0022cf625f8f4ad912..319edc23996275361e908e6557264b81c8b861d1 100644 GIT binary patch delta 41 zcmV+^0M`H71@Hy10RjY^0O-Aw1p>YlVE4lSfOHB_ur0I>%@A1k+vvmplfeQRV>J?B delta 40 scmeysdW&@fBNNO2|1YLYW@XwZ&Hx4;sX00MItu0aML8*o3RW%*041LcoB#j- 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