1 %define CURRENT_ADDR cs:di
3 ; Prints a null terminated string of your choice.
5 ; CS:DI - pointer to the string you want to print
8 mov ah, 0Eh ; teletype print
10 mov al, [CURRENT_ADDR] ; get current char and put it in al
11 cmp al, 0 ; check if al is null (string terminator)
12 je .done ; if it is, start a new line
13 int 10h ; otherwise write the char
14 inc di ; increment pointer to string
15 jmp .write2 ; jump back to this section
17 mov al, 0Dh ; carriage return
19 mov al, 0Ah ; line feed
24 ; Prints a word (16-bit value) in hex format.
28 pusha ; push all regs to stack
29 mov di, HEX_OUT+5 ; set destination index to last char in HEX_OUT
30 mov ax, dx ; copy argument to accumulator
31 and al, 00001111b ; extract the low nibble of the low half of the accumulator
32 call .compare ; fill in the string with correct value
33 dec di ; decrement string pointer
34 mov ax, dx ; copy argument to accumulator
35 and al, 11110000b ; extract high nibble of low half of accumulator
36 shr al, 4 ; shift high nibble to low nibble
37 call .compare ; fill in string with correct value
39 mov al, ah ; copy high portion of accumulator to low
48 call print ; write string
53 cmp al, 0 ; compare al with 0
54 jne .one ; if not equal, compare with 1
55 mov byte [CURRENT_ADDR], '0' ; set character to ASCII 0
60 mov byte [CURRENT_ADDR], '1'
65 mov byte [CURRENT_ADDR], '2'
70 mov byte [CURRENT_ADDR], '3'
75 mov byte [CURRENT_ADDR], '4'
80 mov byte [CURRENT_ADDR], '5'
85 mov byte [CURRENT_ADDR], '6'
90 mov byte [CURRENT_ADDR], '7'
95 mov byte [CURRENT_ADDR], '8'
100 mov byte [CURRENT_ADDR], '9'
105 mov byte [CURRENT_ADDR], 'A'
110 mov byte [CURRENT_ADDR], 'B'
115 mov byte [CURRENT_ADDR], 'C'
120 mov byte [CURRENT_ADDR], 'D'
125 mov byte [CURRENT_ADDR], 'E'
128 mov byte [CURRENT_ADDR], 'F'
131 HEX_OUT: db "0x0000", 0