-
Notifications
You must be signed in to change notification settings - Fork 199
/
debug.asm
73 lines (57 loc) · 1.6 KB
/
debug.asm
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
;asmttpd - Web server for Linux written in amd64 assembly.
;Copyright (C) 2014 nemasu <[email protected]>
;
;This file is part of asmttpd.
;
;asmttpd is free software: you can redistribute it and/or modify
;it under the terms of the GNU General Public License as published by
;the Free Software Foundation, either version 2 of the License, or
;(at your option) any later version.
;
;asmttpd is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with asmttpd. If not, see <http://www.gnu.org/licenses/>.
;hint, use these with GDB
;set follow-fork-mode child
section .bss
printbuffer: resb 1024;debug
section .text
print_rdi:
stackpush
push rax
push rbx
push rcx
call get_number_of_digits
mov rcx, rax ;
inc rax ;include NL char in length
push rax; save length for syscall
;add lf
mov rdx, 0xa
mov [printbuffer+rcx], dl
dec rcx
mov rax, rdi ; value to print
xor rdx, rdx ; zero other half
mov rbx, 10
print_rdi_start:
xor rdx, rdx ; zero other half
div rbx ; divide by 10
add rdx, 0x30
mov [printbuffer+rcx], dl
dec rcx
cmp rax, 9
ja print_rdi_start
add rax, 0x30 ;last digit
mov [printbuffer+rcx], al
pop rcx ;restore original length
mov rdi, printbuffer
mov rsi, rcx
call sys_write
pop rcx
pop rbx
pop rax
stackpop
ret