Signed int print
This commit is contained in:
parent
c9d26b0a4e
commit
b42a2bda0c
11
main.asm
11
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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
@ -152,20 +168,20 @@ 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
|
||||
print_sint:
|
||||
pusha
|
||||
|
||||
%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
|
||||
; 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
|
Loading…
Reference in a new issue