I’ve been relearning and writing some assembly code, very basic stuff for starters. I’m on running Ubuntu on x86_64, but the tutorials I’m following along with were done on 32-bit x86.
I’ve included the short assembly program below, which assembles and links fine, but segfaults when running it. I’m betting my error is some mixup/confusion with respect to the lines between 32 and 64 bit instructions and memory usage. For example, I am using movq instructions on all the r** registers (x86_64 version of 32 bit registers from what I’ve gathered) – but perhaps that is in error.
I’d really appreciate it if someone is able to explain the problem here, I feel like if I better understood the cause it would really help avoid these types of problems in the future.
.data
Bash:
.asciz "/bin/bash"
Null1:
.int 0
AddrToBash:
.int 0
Null2:
.int 0
.text
.globl _start
_start:
movq $Bash, AddrToBash
movq $59, %rax
movq $Bash, %rbx
movq $AddrToBash, %rcx
movq $Null2, %rdx
syscall
Exit:
movq $60, %rbx
movq $1, %rax
syscall
Thanks in advance!
%rsi,%rdi,%rdx. See What are the calling conventions for UNIX & Linux system calls on x86-64..int 0is too short, should be.quad 0in all three places.