code:
extern printf
extern scanf
extern puts
global main
section .rodata
msg1 db "Enter positive Number:",0
arg1 db "%s",0
arg2 db "%u",0
section .text
main:
push rbp
mov rbp , rsp
sub rsp , 8 ; what is purpose of this stack allign
xor rax , rax ; no floating point
mov rdi , arg1
mov rsi , msg1
call printf
;How can i call from scanf using stack
add rsp , 8
pop rbp
ret
I tried something like
1)
xor rax , rax
mov rdi , arg2
lea rsi , [rsp+4] ;first four byte
call scanf
2)
xor rax , rax
mov rdi , arg2
mov rsi , rsp ;last four byte
call scanf
3)
sub rsp , 4
xor rax , rax
mov rdi , arg2
mov rsi , rsp ;newely allocated 4 byte
call scanf
add rsp , 4
4)
xor rax , rax
mov rdi , arg2
lea rsi , [rsp-4] ;newely allocated 4 byte
call scanf
This all are throws Segmentation fault (core dumped)
1)What is the perfect way to call scanf or printf from assembly
I am using nasm(assembler) and gcc(linker) with kali linux subsystem(wsl) in windows x86-64(64 bit)
Thanks.