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
|
section KERNEL follows=BOOTSECTOR vstart=1000h
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov bx, 65535
|
mov bx, 156
|
||||||
call print_uint
|
call print_sint
|
||||||
|
|
||||||
|
;mov ax, -20
|
||||||
|
;mov dx, 0x0003
|
||||||
|
;mov cx, 10
|
||||||
|
;idiv cx
|
||||||
|
;mov bx, ax
|
||||||
|
;call print_uint
|
||||||
|
|
||||||
jmp $ ; Halt
|
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:
|
print:
|
||||||
pusha
|
pusha
|
||||||
|
|
||||||
|
@ -128,7 +144,7 @@ print_uint:
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
mov cx, 10
|
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
|
div cx ; Divide ax by cx (10), -> ax, rem -> dx
|
||||||
|
|
||||||
add dx, 0x30 ; Add ascii '0'
|
add dx, 0x30 ; Add ascii '0'
|
||||||
|
@ -151,21 +167,21 @@ print_uint:
|
||||||
|
|
||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
_print_dec_buff: resb 6
|
print_sint:
|
||||||
|
pusha
|
||||||
%macro print_ch 1
|
|
||||||
push ax
|
; Old (non-working method) used a copy of above with idiv. I think this way is smarter
|
||||||
mov al, [%1]
|
|
||||||
mov ah, 0x0e
|
test bx, 0x8000 ; Check sign-bit
|
||||||
int 0x10
|
jz .positive
|
||||||
pop ax
|
|
||||||
%endmacro
|
print_ch '-'
|
||||||
|
neg bx
|
||||||
%macro cls 0
|
|
||||||
mov ax, 0x0600 ; AH=06 Scroll screen, AL=0 Clear screen
|
.positive:
|
||||||
mov bh, 0x0F ; black bg, white fg
|
call print_uint
|
||||||
mov cx, 0x0000 ; x1=y1=0
|
|
||||||
mov dx, 0x5019 ; 89x25
|
popa
|
||||||
int 0x10 ; Graphics services
|
ret
|
||||||
%endmacro
|
|
Loading…
Reference in a new issue