]> git.dujemihanovic.xyz Git - nameless-os.git/blob - print.s
ab6eef4c92c9a66441c0abd6c1999ddc61af5bd3
[nameless-os.git] / print.s
1 %define CURRENT_ADDR cs:di
2
3 print_word:
4 pusha ; push all regs to stack
5 mov di, HEX_OUT+5 ; set destination index to last char in HEX_OUT
6 mov ax, dx ; copy argument to accumulator
7 and al, 00001111b ; extract the low nibble of the low half of the accumulator
8 call .compare ; fill in the string with correct value
9 dec di ; decrement destination index
10 mov ax, dx ; copy argument to accumulator
11 and al, 11110000b ; extract high nibble of low half of accumulator
12 shr al, 4 ; shift high nibble to low nibble
13 call .compare ; fill in string with correct value
14 dec di
15 mov al, ah ; copy high portion of accumulator to low
16 and al, 00001111b ;
17 call .compare
18 dec di
19 mov al, ah
20 and al, 11110000b
21 shr al, 4
22 call .compare
23 jmp .write ; write string
24
25 .write:
26 popa ; get back our arguments
27 mov dl, cl ; column
28 mov dh, ch ; row
29 pusha ; save registers
30 mov al, 1 ; update cursor
31 mov bh, 0 ; page number
32 mov bl, 00000111b ; colors
33 mov cx, 6 ; length of string
34 push cs ; push code segment address
35 pop es ; pop to extra segment address
36 mov bp, HEX_OUT ; offset to extra segment of string
37 mov ah, 13h ; write string
38 int 10h ; BIOS interrupt
39 popa
40 ret ; return
41
42 .compare:
43 cmp al, 0 ; compare al with 0
44 jne .one ; if not equal, compare with 1
45 mov byte [CURRENT_ADDR], '0' ; set character to ASCII 0
46 ret ; return
47 .one:
48 cmp al, 1
49 jne .two
50 mov byte [CURRENT_ADDR], '1'
51 ret
52 .two:
53 cmp al, 2
54 jne .three
55 mov byte [CURRENT_ADDR], '2'
56 ret
57 .three:
58 cmp al, 3
59 jne .four
60 mov byte [CURRENT_ADDR], '3'
61 ret
62 .four:
63 cmp al, 4
64 jne .five
65 mov byte [CURRENT_ADDR], '4'
66 ret
67 .five:
68 cmp al, 5
69 jne .six
70 mov byte [CURRENT_ADDR], '5'
71 ret
72 .six:
73 cmp al, 6
74 jne .seven
75 mov byte [CURRENT_ADDR], '6'
76 ret
77 .seven:
78 cmp al, 7
79 jne .eight
80 mov byte [CURRENT_ADDR], '7'
81 ret
82 .eight:
83 cmp al, 8
84 jne .nine
85 mov byte [CURRENT_ADDR], '8'
86 ret
87 .nine:
88 cmp al, 9
89 jne .ten
90 mov byte [CURRENT_ADDR], '9'
91 ret
92 .ten:
93 cmp al, 0Ah
94 jne .eleven
95 mov byte [CURRENT_ADDR], 'A'
96 ret
97 .eleven:
98 cmp al, 0Bh
99 jne .twelve
100 mov byte [CURRENT_ADDR], 'B'
101 ret
102 .twelve:
103 cmp al, 0Ch
104 jne .thirteen
105 mov byte [CURRENT_ADDR], 'C'
106 ret
107 .thirteen:
108 cmp al, 0Dh
109 jne .fourteen
110 mov byte [CURRENT_ADDR], 'D'
111 ret
112 .fourteen:
113 cmp al, 0Eh
114 jne .fifteen
115 mov byte [CURRENT_ADDR], 'E'
116 ret
117 .fifteen:
118 mov byte [CURRENT_ADDR], 'F'
119 ret
120
121 HEX_OUT: db "0x0000"