SteveOS for 16 bit processors (286)

print.asm 1.6KB

    ;; ax - number in print_hex: pusha mov [hex_count], byte 0 print_hex_digit: mov dx, 0 mov bx, 16 div bx ;ax/16 ;; dx = remainder ;; ax = answer push ax cmp dx, 9 jg hex_digit ;A-F add dl, '0' mov bx, hex_buffer add bx, [hex_count] mov [bx], dl add [hex_count], byte 1 jmp print_hex_next hex_digit: add dl, 0x37 mov bx, hex_buffer add bx, [hex_count] mov [bx], dl add [hex_count], byte 1 ;;jmp print_hex_digit print_hex_next: pop ax cmp ax, 0 jg print_hex_digit ;more digits ;; add '0x' mov al, '0' call print_char mov al, 'x' call print_char ;; output buffer... in reverse mov bx, hex_buffer add bx, [hex_count] output_digit: sub bx, 1 mov al, [bx] call print_char sub [hex_count], byte 1 cmp [hex_count], byte 0 jne output_digit ;; done popa ret ;;;END print hex hex_buffer: times 5 db 0 hex_count: dw 0 ;; Pass pointer to string @bx ;; Pass colour into cx print: pusha mov ah, 0x0E ;Teletype output print_cont: mov al, [bx] cmp al, 0 je print_end xchg cx, bx int 0x10 ;print the character xchg bx, cx inc bx jmp print_cont ;One less instruction per print print_end: popa ret ;; Pass character @al print_char: pusha mov ah, 0x0E int 0x10 popa ret ;; Prints an array of strings ;; bx - array of pointers to strings ;; al - char to print out between strings print_array: pusha print_array_cont: cmp [bx], word 0 je print_array_done push bx mov bx, [bx] call print pop bx ;; al is already set call print_char add bx, 2 jmp print_array_cont print_array_done: popa ret