Reputation: 19881
Using FASM, x86_64, Linux (Mint)
Passing args to C function
int arg_test(int argc, char *argv[]) {
// output number of args
printf("arg count: %d\n", argc);
printf("%s", *argv);
return TRUE;
}
The assembly executable
public main
section '.text'
extrn arg_test
main:
mov rdi, 2 ; 1st parameter (number of args)
mov rsi, .arg1 ; [0] 2nd parameter
mov rdx, 0 ; [1] 3rd parameter (null)
xor rax, rax
call arg_test
mov eax, syscall_exit
xor edi, edi
syscall
section '.data'
.arg1: db "arg1", 0
...The output
arg count: 2
Segmentation fault (core dumped)
What am I missing about passing args to the C function? How can I properly iterate the arguments?
Upvotes: 0
Views: 95