Reputation: 6751
I'm currently trying to learn assembly on my Trisquel distribution (which I guess uses Ubuntu under the hood?). For some reason, I'm stuck on the very first step of creating and executing a assembly snippet.
.section data
.section text
.globl _start
_start:
movl $1, %eax # syscall for exiting a program
movl $0, %ebx # status code to be returned
int $0x80
When I try to assemble and link it for creating an executable and run the executable, I get something like:
> as myexit.s -o myexit.o && ld myexit.o -o myexit
> ./myexit
bash: ./myexit: cannot execute binary file
I'm not sure what exactly is going on here. After searching around, it seems that this error usually pops up when trying to execute 32 bit executable on a 64 bit OS or maybe vice-versa which isn't the case for me.
Here is the output of file
and uname
command:
$ file myexit
myexit: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
$ uname -a
Linux user 2.6.35-28-generic #50trisquel2-Ubuntu SMP Tue May 3 00:54:52 UTC 2011 i686 GNU/Linux
Can someone help me out in understanding what exactly is going wrong here? Thanks.
Upvotes: 2
Views: 3734
Reputation: 206659
.section text
is incorrect, that creates a section called text
when you need your code to be in the .text
section. Replace that with:
.data
.text
.globl _start
_start:
...
Upvotes: 4