From 523322dc13a2599014e26780518bf06277a57e30 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 29 Nov 2017 11:34:58 -0500 Subject: add print[i,h] and normalize load addresses --- stdio.asm | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'stdio.asm') 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 -- cgit