I am trying to learn how to use .s
files, and wrote the following:
.globl main
.text
main:
mov $msg, %rdi
call puts
ret
.data
msg:
.asciz "Hello, world!"
I then compile with the following:
$ gcc -no-pie -c -o example.o example.s
$ gcc -no-pie -o example example.s
The example
executable produced prints Hello, world!
as expected, but exits with exit code 14
, suggesting that something went wrong regarding the print?
I tried exiting manually like so:
.globl main
.text
main:
mov $msg, %rdi
call puts
mov 0, %rdi
call exit
ret
.data
msg:
.asciz "Hello, world!"
However, this segfaulted. From gdb
, it seems to segfault on the line mov 0, %rdi
, however I've tried multiple ways of moving (movq 0, %edi
, movl 0, %edi
, mov 0x0, %rdi
) and all have segfaulted.
Am I doing something wrong?