So I have been following some tutorials on assembly and the instructor compiles the following code:
;hello3.asm attempts to make the code position independent
section .text
global _start
_start:
;clear out the registers we are going to need
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
;write(int fd, char *msg, unsigned int len)
mov al, 4
mov bl, 1
;Owned!!! = 4f,77,6e,65,64,21,21,21
;push !,!,!,d
push 0x21212164
;push e,n,w,O
push 0x656e774f
mov ecx, esp
mov dl, 8
int 0x80
;exit(int ret)
mov al,1
xor ebx, ebx
int 0x80
Note that the message Owned!!!
is pushed into the stack rather than kept in the .text
segment. So, when I try to execute it, I get a Segment Fault
error!
If instead I keep the message in the .text
, then, everything works fine.
The commands I used to execute:
$> nasm -f elf64 hello4.asm
$> ld -o hello hello4.o
Any ideas?