3

I recently started reading Programing From The Ground Up (PDF), but I've run into an issue in the first program. The program is very simple:

.section .data
.section .text

.globl _start

_start:
    movl    $1, %eax
    movl    $0, %ebx
    int     $0x80

But in compiling and running I get the error Illegal Instruction: 4. I did edit the program so that it would compile properly (removed the two .sections and changed _start to _main) so that may have affected it.

I am using the x86_64 instruction set (Intel processor).

nrz
  • 10,435
  • 4
  • 39
  • 71
Jumhyn
  • 6,687
  • 9
  • 48
  • 76
  • This code works fine for me (on Linux). What OS are you on? Although, why do you call `fork` (2) syscall? Maybe, you need `exit` syscall (1)? – kharvd Feb 19 '12 at 19:25
  • Ah, that was a typo. Im on Mac OS 10.7. Changing it to 1 didn't help. How are you compiling? I've just been using `gcc`. – Jumhyn Feb 19 '12 at 19:31
  • That compiles alright, but when linking: `$ ld exit -o exit/ ld: warning: -macosx_version_min not specificed, assuming 10.7/ Undefined symbols for architecture x86_64:/ "start", referenced from:/ -u command line option/ (maybe you meant: _start)/ ld: symbol(s) not found for inferred architecture x86_64` – Jumhyn Feb 19 '12 at 19:36
  • If your code is in exit.s, try `as exit.s -o exit.o && ld exit.o -o exit` – kharvd Feb 19 '12 at 19:42
  • can some one point our what is the meaning of .section data,.section text, and movl $1,%eax does the instruction movl $1,%eax stores the system call or system call corresponding to value $1 is stored in $eax – Registered User Jan 06 '13 at 04:01

1 Answers1

3

If you are using x86-64, you need to change the ABI slightly, see this. For a very nice summary of the differences, see this post.

Community
  • 1
  • 1
Necrolis
  • 25,836
  • 3
  • 63
  • 101