about summary refs log tree commit diff stats
path: root/example/samples/human.S
blob: 6cdeab0fe206a224f4de335cc41bada324167b47 (plain) (blame)
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
	;;  Walk a human link list and print its information
main:
	TEST       RDI, RDI
	JZ         next

	PUSH       RBX
	MOV        RBX, RDI
loop_arg:
	LEA        RSI, QWORD PTR [RBX+0x10]
	LEA        RDI, QWORD PTR [name-_+RIP]
	XOR        EAX, EAX
	CALL       printf

	MOVZX      ESI, WORD PTR [RBX+0x8]
	LEA        RDI, QWORD PTR [age-_+RIP]
	XOR        EAX, EAX
	CALL       printf

	MOV        ESI, DWORD PTR [RBX+0xC]
	XOR        EAX, EAX
	LEA        RDI, QWORD PTR [height-_+RIP]
	CALL       printf

	MOV        RBX, QWORD PTR [RBX]
	TEST       RBX, RBX
	JNZ        loop_arg

	POP        RBX
next:


	LEA        RBX, QWORD PTR [struct_human_ptr-_+RIP]
loop_global:
	CMP        RBX, 0
	JZ         end

	LEA        RSI, QWORD PTR [RBX+0x10]
	LEA        RDI, QWORD PTR [name-_+RIP]
	XOR        EAX, EAX
	CALL       printf
	MOV        RBX, QWORD PTR [RBX]
	JMP        loop_global
end:
	RET

printf:
	;; Dummy printf
	RET

age:
.string "Age: %d\n"
height:
.string "Height: %d\n"
name:
.string "Name: %s\n"
struct_human_ptr:
.dword 0xdead, 0xcafe