I am using Ubuntu 14.04 and Terminal.
I am doing an assembly language exercise for a class. I wanted to try running this in terminal, but I am unable to link this file. [I think 'link' is the correct terminology for using the command gcc -o ex71 ex71.s
but I am new to assembly language and GNU/Linux so I may be mistaken]. Below is my .s file.
I first type as -gstabs -o ex71.o ex71.s
into terminal which is what my textbook does [to create an object file right?]. Then I type the gcc -o ex71 ex71.s
command. Then I would type ./ex71
but I get a long error with gcc -o ex71 ex71.s
telling me relocation ## has invalid symbol index ##
. At the end of the error, it says undefined reference to 'main'
.
Sample of the output error message demonstrating its form:
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
Source code:
# ex71.s
# Minimum components of a C program, in assembly language
# Copied from Bob Plantz
#
# comment lines placed to correspond with textbook
.text
.globl f
.type f, @function
f:
pushq %rbp # save caller's frame pointer
movq %rsp, %rbp # establish our frame pointer
movl $0, %eax # return 0 to caller
movq %rbp, %rsp # restore stack pointer
popq %rbp # restore caller's frame pointer
ret # back to caller