-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommonSubroutines.nasm
102 lines (97 loc) · 1.32 KB
/
commonSubroutines.nasm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
; args: al = char, bl = attibute, bh = page, dl = cursor x, dh = cursor y
; invalidates: ah, cx
printChar:
mov cx, 1
mov ah, 2
int 10h
mov ah, 9
int 10h
inc dl
ret
; args: ax = address to string, bl = attibute, bh = page, dl = cursor x, dh = cursor y
; invalidates: ax, cx, si
printString:
mov si, ax
mov cx, 1
.loop:
mov al, [si]
test al, al
jz .end
mov ah, 2
int 10h
mov ah, 9
int 10h
inc dl
inc si
jmp .loop
.end:
ret
; args: al = number to print, bl = attibute, bh = page, dl = cursor x, dh = cursor y
; invalidates: ax, cx
printNumDec:
test al, al
jnz .print_ax
push ax
mov al, '0'
mov ah, 2
int 10h
mov cx, 1
mov ah, 9
int 10h
inc dl
pop ax
ret
.print_ax:
push ax
push cx
mov ah, 0
cmp ax, 0
je .pn_done
mov cl, 10
div cl
call .print_ax
mov al, ah
add al, 30h
mov ah, 2
int 10h
push cx
mov cx, 1
mov ah, 9
int 10h
pop cx
inc dl
.pn_done:
pop cx
pop ax
ret
; args: ax = number to print, bl = attibute, bh = page, dl = cursor x, dh = cursor y
printNumHex:
push cx
push si
mov cx, ax
rol cx, 4
mov si, 3
.loop:
mov ah, 2
int 10h
mov al, cl
and al, 0Fh
cmp al, 10
jns .letter
add al, '0'
jmp .print
.letter:
add al, ('A' - 10)
.print:
mov ah, 9
push cx
mov cx, 1
int 10h
pop cx
rol cx, 4
inc dl
dec si
jns .loop
pop si
pop cx
ret