-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.asm
More file actions
119 lines (98 loc) · 1.5 KB
/
Copy pathcount.asm
File metadata and controls
119 lines (98 loc) · 1.5 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
[BITS 16]
[ORG 0xA000]
SYSCALL_INT equ 0x80
SYS_PUTS equ 0x02
SYS_NEWLINE equ 0x03
SYS_PUTC equ 0x01
start:
mov ax, 0
mov ds, ax
mov es, ax
mov byte [frame_count], 0
mov ax, 1
call print_count
ret
print_count:
; print AX
push ax
call print_u16_dec
call sys_newline
pop ax
inc byte [frame_count]
cmp byte [frame_count], 10
jne .skip_sp
mov byte [frame_count], 0
mov [saved_sp], sp
push ax
mov ax, [saved_sp]
call print_sp_hex
call sys_newline
pop ax
.skip_sp:
; recurse with AX + 1
inc ax
call print_count
ret
sys_putc:
mov ah, SYS_PUTC
int SYSCALL_INT
ret
sys_newline:
mov ah, SYS_NEWLINE
int SYSCALL_INT
ret
print_sp_hex:
push ax
mov al, ah
call print_hex8
pop ax
call print_hex8
ret
print_hex8:
push ax
shr al, 4
call print_hex_digit
pop ax
call print_hex_digit
ret
print_hex_digit:
and al, 0x0F
cmp al, 0x0A
jl .is_digit
add al, 'A' - 0x0A
jmp .print_it
.is_digit:
add al, '0'
.print_it:
mov ah, SYS_PUTC
int SYSCALL_INT
ret
print_u16_dec:
push ax
push bx
push cx
push dx
xor cx, cx
mov bx, 10
.convert:
xor dx, dx
div bx
push dx
inc cx
test ax, ax
jnz .convert
.print_loop:
pop dx
add dl, '0'
mov al, dl
call sys_putc
loop .print_loop
pop dx
pop cx
pop bx
pop ax
ret
frame_count:
db 0
saved_sp:
dw 0