-
Notifications
You must be signed in to change notification settings - Fork 0
/
thing.asm
69 lines (50 loc) · 1012 Bytes
/
thing.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
%include "./generated/std.asm"
section .bss
digitSpace resb 100
digitSpacePos resb 8
argc resb 8
section .data
;; For floating point operations
float_imm dq 0
string_0 db 97,114,114,97,121,91,53,93,32,61,32
section .text
global _start
_start:
mov [argc], rsp
call _main
exit 0
_main:
push rbp
mov rbp, rsp
;; Make sure that the stack pointer is 16 byte aligned always
sub rsp, 80
;; Minus get the two operands from the stack
mov rbx, 5
mov rax, 15
sub rax, rbx
mov rbx, rax ;; rbx = 10
;; rcx stores the index, rdx has the actual value
mov rcx, 5 ;; rcx = 5
mov rdx, rbx ;; rdx = 10
mov rax, 8 ;; rax = 8
mul rcx ;; rax = 40
mov rcx, rbp ;; rcx = rbp
add rcx, rax ;; rcx = rbp + 40
mov [rcx - 80], rdx ;; rbp - 40 = 10
mov rax, 1
mov rdi, 1
mov rsi, string_0
mov rdx, 11
syscall
;; Start array index access
mov rax, 5
mov rbx, 8
mul rbx
mov rbx, rbp
add rbx, rax
mov rax, [rbx - 80]
mov rax, rax
call _printRAX
mov rsp, rbp
pop rbp
ret