How can I pass array of strings as parameter to function in assembler? For example lets say I want to call execve() function which looks like this:
int execve(const char *filename, char *const argv[], char *const envp[]);
so I do this:
test.asm
format elf executable
entry main
main:
mov eax, 11 ; execve - executes program
mov ebx, filename ; label name is address of string variable
mov ecx, args ; label name is address of array of strings?
mov edx, 0 ; NULL
int 80h
mov eax, 1 ;exit
int 80h
ret
filename db '/bin/ls', 0 ; path to program
args db '/bin/ls', 0, '.', 0, 0 ; array should end with empty string to
; indicate end of array
makefile
all:
~/apps/fasm/fasm ./test.asm
But when I run my program execve() fails to execute requested program and strace ./test shows this message:
execve("/bin/ls", [0x6e69622f, 0x736c2f, 0x2e], [/* 0 vars */]) = -1 EFAULT (Bad address)
How to properly pass "args" variable to execve function?
Thanks :)
lea ebx, [ filename ]to move the address of a label into a register.