-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclib.asm
43 lines (36 loc) · 851 Bytes
/
clib.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
; AUTHOR: ASHWIN ABRAHAM
; This code prints out the number of command line arguments it recieves and then prints these arguments
; This code demonstrates the ability to call C library functions from an assembly program
section .rodata
format db 'Number of command line arguments', 58, ' %d', 10, 'Command Line Arguments', 58, 10, 0; 58 is ':' and 10 is '\n'
section .text
global main
extern printf
extern puts
main:
push rbp
mov rbp, rsp
push rdi
push rsi
mov esi, edi
mov rdi, format
call printf WRT ..plt
pop rsi
pop rdi
mov ecx, edi
mov eax, edi
.1:
push rcx
push rax
push rsi
sub eax, ecx
mov rdi, [rsi+8*rax]
call puts WRT ..plt
pop rsi
pop rax
pop rcx
loop .1
xor eax, eax
;mov rsp, rbp
pop rbp
ret