blob: 451622398eaeb81fbed4eb62bb18015db03cbf37 (
plain)
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
|
%ifndef ZSTRING_INC
%define ZSTRING_INC
%ifndef SYS_INC
%include "sys.inc"
%endif
%macro make_zstring 2-*
section .data
%1: db %2
%rep %0-2
db %3
%rotate 1
%endrep
db 0
%endm
section .text
length_zstring:
;; rax = zstring address
push rbp
mov rbp, rsp
;;
mov rdx, rax
xor rax, rax
.loop:
mov cl, byte [rdx]
cmp cl, 0
je .exit
inc rax
inc rdx
jmp .loop
.exit:
;;
mov rsp, rbp
pop rbp
ret
print_zstring:
;; rax = zstring address
push rbp
mov rbp, rsp
;;
push rax
mov rsi, rax
call length_zstring
mov rdx, rax
mov rax, SYS_WRITE
mov rdi, 1
syscall
;;
mov rsp, rbp
pop rbp
ret
%endif
|