Skip to content
Snippets Groups Projects
print.asm 828 B
Newer Older
Jeremy Soller's avatar
Jeremy Soller committed
SECTION .text
USE16
; provide function for printing in x86 real mode

; print a string and a newline
; CLOBBER
;   ax
print_line:
    mov al, 13
    call print_char
    mov al, 10
    jmp print_char
Jeremy Soller's avatar
Jeremy Soller committed

; print a string
; IN
;   si: points at zero-terminated String
; CLOBBER
Jeremy Soller's avatar
Jeremy Soller committed
;   si, ax
Jeremy Soller's avatar
Jeremy Soller committed
print:
Jeremy Soller's avatar
Jeremy Soller committed
    pushf
Jeremy Soller's avatar
Jeremy Soller committed
    lodsb
    test al, al
    jz .done
    call print_char
Jeremy Soller's avatar
Jeremy Soller committed
.done:
Jeremy Soller's avatar
Jeremy Soller committed
    popf
Jeremy Soller's avatar
Jeremy Soller committed
    ret

; print a character
; IN
;   al: character to print
print_char:
Jeremy Soller's avatar
Jeremy Soller committed
    pusha
    mov bx, 7
Jeremy Soller's avatar
Jeremy Soller committed
    mov ah, 0x0e
    int 0x10
Jeremy Soller's avatar
Jeremy Soller committed
    popa
Jeremy Soller's avatar
Jeremy Soller committed
    ret

; print a number in hex
; IN
;   bx: the number
; CLOBBER
Jeremy Soller's avatar
Jeremy Soller committed
;   al, cx
print_hex:
Jeremy Soller's avatar
Jeremy Soller committed
    mov cx, 4
.lp:
    mov al, bh
    shr al, 4

    cmp al, 0xA
    jb .below_0xA

    add al, 'A' - 0xA - '0'
.below_0xA:
    add al, '0'

    call print_char

    shl bx, 4
    loop .lp

    ret