linux - gcc compiling assembly on ubuntu -
on first assignment of course we've been asked try compile simple assembly file on ubuntu terminal using following line:
gcc hello.s ./a.out
here code inside file:
#this simple "hello world!" program .section .rodata #read data section str: .string "hello world!\n" ######## .text #the beginning of code .globl main #the label "main" used state initial point of program .type main, @function # label "main" representing beginning of function main: # main function: pushq %rbp #save old frame pointer movq %rsp, %rbp #create new frame pointer movq $str,%rdi #the string parameter passed printf function (remember- first parameter goes in %rdi). movq $0,%rax call printf #calling printf after passed parameters. #return printf: movq $0, %rax #return value 0 (just in c - tell os program finished successfully) movq %rbp, %rsp #restore old stack pointer - release used memory. popq %rbp #restore old frame pointer (the caller function frame) ret #return caller function (os)
but after compilation printed on terminal:
"/usr/bin/ld: /tmp/ccm5bvmg.o: relocation r_x86_64_32s against `.rodata' can not used when making shared object; recompile -fpic /usr/bin/ld: final link failed: nonrepresentable section on output collect2: error: ld returned 1 exit status"
i've looked on web problem , tried compile flag, still nothing.
Comments
Post a Comment