-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinting.asm
More file actions
77 lines (66 loc) · 930 Bytes
/
Copy pathprinting.asm
File metadata and controls
77 lines (66 loc) · 930 Bytes
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
%define base_10 10
section .data
_linebreak db 10
section .bss
_char_print_buffer: resb 1
global print
global print_char
global print_newline
global print_c_string
global print_u64
section .text
print:
mov rdi, STDOUT ; fd
mov rax, SYS_WRITE ; write(2)
syscall
ret
print_char:
mov rdx, 1
call print
ret
print_newline:
mov rsi, _linebreak
call print_char
ret
print_c_string:
xor rax, rax
mov r11, rdi
_count_length:
mov cl, [r11]
cmp cl, 0
jz _length_counted
inc rax
inc r11
jmp _count_length
_length_counted:
mov rsi, rdi
mov rdx, rax
call print
ret
print_u64:
xor r8, r8
xor r9, r9
xor rdx, rdx
mov rcx, base_10
mov rax, rdi
_next_digit:
xor rdx, rdx
div rcx
and rdx, 0xFF
add rdx, '0'
inc r9
shl r8, 8
add r8, rdx
cmp rax, 0
jnz _next_digit
push r8
mov r8, rsp
mov rsi, r8
mov rdx, r9
call print
pop r8
ret
; file descriptors
STDOUT EQU 1
; syscalls
SYS_WRITE EQU 1