i got some problems with assembly code. I'm trying to call C function print. I compile file with:
gcc helloC.s -o hello
And i got error like:
/tmp/cc0SwfB8.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
This is a program given by our professor. I'm compiling by putty on univesity computer. Linux function: lscpu says it is x86_64 architecture.
Code given by our professor:
#PURPOSE: This program writes the message "hello world" and
# exits
#
.section .data
helloworld:
.ascii "hello world\n\0"
.section .text
.globl _start
_start:
main:
pushq $helloworld
call printf
pushq $0
call exit
The only thing i changed in this code is push -> pushq because of 64bit architecture.
Edit: as fuz said i changed .globl _start to .globl main. Olso i changed label _start: to main: I compiles without error.
When i lunch program with ./hello it says something like :"Memory protection violation" (translated form my native language. (Naruszenie ochrony pamięci))
#PURPOSE: This program writes the message "hello world" and
# exits
#
.section .data
helloworld:
.ascii "hello world\n\0"
.section .text
.globl main
main:
pushq $helloworld
call printf
pushq $0
call exit