-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.s
56 lines (53 loc) · 1.14 KB
/
out.s
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
[BITS 64]
section .text
global _start
_start:
call main
mov rdi, rax
mov rax, 60
syscall
global main
main:
push rbp ;save previous base pointer
push rbx ;functions should preserve rbx
mov rbp, rsp ;set base pointer
mov rax, 5
push rax
mov rax, 4
push rax
mov rax, 3
push rax
mov rax, rsp ; Move the address of the array to rax
mov rax, rsp
add rax, 24
push rax
mov rax, 'b'
pop rcx
add rsp, 8
push rax
mov rax, rcx
sub rax, 24
push rax
mov rax, 'a'
pop rcx
add rsp, 8
push rax
mov rax, rcx
mov rax, rsp ; Move the address of the array to rax
push rax
mov rax, [rbp-64]
mov rcx, 1
mov rax, [rax + rcx * 8]
push rax
mov rax, 1
pop rcx
mov rax, [rcx + rax * 8]
add rsp, 64 ;pop local variables before return
pop rbx ;restore rbx for caller function
pop rbp ;restore base pointer
ret
add rsp, 8 ;end of block, pop local variables
pop rbx ;restore rbx for caller function
pop rbp ;restore base pointer
ret ;return by default if no return statement was reached
section .data