Im having a bit of trouble understanding the more complex system calls in assembly. I wrote a exec system call and it worked great
.bss
.text
.globl _start
_start:
#exit(0) system call
movl $1, %rax
movl $0, %rbx
int $0X80
Though I am a bit insure and have not been able to find info pertaining to how you put strings in a register. So as an example I wanted to do a exec system call and it as its first parameter needs a filename to run and I want to run "/bin/bash", but how do I get that in rbx. How do I even know that I have to use rbx, in X86 I know I would use ebx, is it the same relationship in amd64 ebx=rbx, ecx=rcs, etc.
int execve(const char *filename, char *const argv[], char *const envp[]);
Thanks all
Here's a trick to make progress quickly with these aspects of assembly: ask a C compiler to show you how it does it! Write a C program that does what you want to do and type
gcc -S
.Example:
then:
You don't put strings in a register. You should pass a pointer (the address) to a null (0) terminated string (C style) in the register for this function. Some system calls (like
write
) take a pointer (not necessarily terminated by'\0'
) and length in two registers.and pass
$myString
using the register.