-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-stack-pointer.asm
More file actions
65 lines (54 loc) · 1.81 KB
/
Copy pathstack-stack-pointer.asm
File metadata and controls
65 lines (54 loc) · 1.81 KB
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
extern printText
section .text
global pushAndPopArrayOnTheStack
pushAndPopArrayOnTheStack:
mov rbx, 3472
push rbx
mov rbx, 1072
push rbx
mov rbx, 282
push rbx
mov rbx, 728902
push rbx
mov rbx, 560
push rbx
mov rbx, 12333
push rbx
mov rbx, 259
push rbx
; the stack is 56 bytes in size at this point
; +8 bytes that will be added for return address = 64 bytes
; so we are 16 bytes aligned at this point. Linux ABI Happy ;)
;
; one thing that wasn't clear for me before is that before a call
; the CPU pushes 8 bytes for the return address -- we already knew this,
; but, when the called function finishes its execution, i.e, ret is called,
; it pops the return address - erasing the 8 bytes added at function call.
; so any other function calls don't need to be manually aligned if we are
; not manipulating the stack anymore, thus, you can see i just call endlessly
; (not really).
mov rdi, [rsp]
call printText
mov rdi, [rsp + 8]
call printText
mov rdi, [rsp + 16]
call printText
mov rdi, [rsp + 24]
call printText
mov rdi, [rsp + 32]
call printText
mov rdi, [rsp + 40]
call printText
mov rdi, [rsp + 48]
call printText
; we are wiping the stack by moving the stack pointer up
; side comment: this is just beautiful. amazing stuff. marvelous.
; test: try changing this to 48 or anything less than 56 and you'll
; see why you must cleanup after your mess.
; i'll spoil a bit:
; - if you use random number like 50 you'll get General Protection exception
; - if you use an 8 byte aligned number (24, 32, 64, etc) other than 56 you'll
; get a segmentation fault.
; computers are fun and they bring joy to my soul hahaha
add rsp, 56
ret