Let's say I have the following C program:
// hi.c
int main() {
int a = 8;
int b = 13;
return a + b;
}
On linux (x86_64 GNU/Linux), here is how I normally compile and run it:
ubuntu@ip-172-30-1:~/asm$ gcc ./hi.c
ubuntu@ip-172-30-1:~/asm$ ./a.out
ubuntu@ip-172-30-1:~/asm$ echo $?
21
However, I'm having a bit of trouble first compiling it to assembly and then running that. What I am trying now is:
$ gcc -S hi.c
$ head -n 5 hi.s
.file "hi.c"
.text
.globl main
.type main, @function
main:
$ as hi.s -o hi.out
$ ld hi.out -e main -o hi
$ ./hi
Segmentation fault (core dumped)
What am I doing incorrect with assembling/linking/running?