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
6 ; BL - 0 prints newline, otherwise no
9 mov ah, 0Eh ; teletype print
11 mov al, [CURRENT_ADDR] ; get current char and put it in al
12 cmp al, 0 ; check if al is null (string terminator)
13 je .newline ; if it is, start a new line
14 int 10h ; otherwise write the char
15 inc di ; increment pointer to string
16 jmp .write2 ; jump back to this section
20 mov al, 0Dh ; carriage return
22 mov al, 0Ah ; line feed
28 ; Prints a word (16-bit value) in hex format.
31 ; BL - 0 will print a newline, 1 won't
33 pusha ; push all regs to stack
34 mov di, HEX_OUT+5 ; set destination index to last char in HEX_OUT
35 mov ax, dx ; copy argument to accumulator
36 and al, 00001111b ; extract the low nibble of the low half of the accumulator
37 call .compare ; fill in the string with correct value
38 dec di ; decrement string pointer
39 mov ax, dx ; copy argument to accumulator
40 and al, 11110000b ; extract high nibble of low half of accumulator
41 shr al, 4 ; shift high nibble to low nibble
42 call .compare ; fill in string with correct value
44 mov al, ah ; copy high portion of accumulator to low
53 call print ; write string
58 cmp al, 0 ; compare al with 0
59 jne .one ; if not equal, compare with 1
60 mov byte [CURRENT_ADDR], '0' ; set character to ASCII 0
65 mov byte [CURRENT_ADDR], '1'
70 mov byte [CURRENT_ADDR], '2'
75 mov byte [CURRENT_ADDR], '3'
80 mov byte [CURRENT_ADDR], '4'
85 mov byte [CURRENT_ADDR], '5'
90 mov byte [CURRENT_ADDR], '6'
95 mov byte [CURRENT_ADDR], '7'
100 mov byte [CURRENT_ADDR], '8'
105 mov byte [CURRENT_ADDR], '9'
110 mov byte [CURRENT_ADDR], 'A'
115 mov byte [CURRENT_ADDR], 'B'
120 mov byte [CURRENT_ADDR], 'C'
125 mov byte [CURRENT_ADDR], 'D'
130 mov byte [CURRENT_ADDR], 'E'
133 mov byte [CURRENT_ADDR], 'F'
136 HEX_OUT db "0x0000", 0