summaryrefslogtreecommitdiff
path: root/stdio.asm
diff options
context:
space:
mode:
Diffstat (limited to 'stdio.asm')
-rw-r--r--stdio.asm89
1 files changed, 88 insertions, 1 deletions
diff --git a/stdio.asm b/stdio.asm
index e6f7290..2e61afc 100644
--- a/stdio.asm
+++ b/stdio.asm
@@ -17,7 +17,7 @@ puts:
lodsb ; load byte at [si] into al
or al, 0 ; 0 | 0 = 0 (detect null terminator)
je .end
- int 10h ; BIOS video service
+ call putc
jmp .loop
.end:
popa
@@ -25,4 +25,91 @@ puts:
pop bp
ret
+
+printi:
+ push bp
+ mov bp, sp
+
+ mov ax, [bp + 4] ; integer WORD
+ mov cx, 0 ; counter
+ cmp ax, 0
+ je .write_no_pop
+
+.divide:
+ xor dx, dx
+ mov di, 10 ; divisor
+ div di
+
+ push dx
+ inc cx
+ cmp ax, 0
+ jne .divide
+
+ jmp .write
+
+.write_no_pop:
+ or al, 30h
+ call putc
+ jmp .return
+
+.write:
+ pop ax
+
+ or al, 30h
+ call putc
+ dec cx
+ jne .write
+
+.return:
+ mov sp, bp
+ pop bp
+ ret
+
+printh:
+ push bp
+ mov bp, sp
+
+ mov ax, [bp + 4] ; integer WORD
+ mov cx, 0 ; counter
+ cmp ax, 0
+ je .write_no_pop
+
+.divide:
+ xor dx, dx
+ mov di, 16 ; divisor
+ div di
+
+ push dx
+ inc cx
+ cmp ax, 0
+ jne .divide
+
+ jmp .write
+
+.write_no_pop:
+ or al, 30h
+ call putc
+ jmp .return
+
+.write:
+ pop ax
+ cmp al, 10
+ jge .alpha
+
+ or al, 30h
+ jmp .decimal
+
+.alpha:
+ sub al, 10
+ add al, 'A'
+
+.decimal:
+ call putc
+ dec cx
+ jne .write
+
+.return:
+ mov sp, bp
+ pop bp
+ ret
%endif