0
.globl _start
_start:

mov $3,%ah     
mov $5,%al

add %ah,%al

movl $0,%ebx
int 0x80

I assemble and link like this without errors:

as file.s -o file.o
ld file.o -o file

but if I run it ./file then it gives me segmentation error.

I've searched it up but I dont get where I did wrong (newbie here..?) please help....

fuz
  • 88,405
  • 25
  • 200
  • 352
SoHungry
  • 1
  • 1
  • What do you expect the `int 0x80` to do? – interjay Nov 11 '21 at 14:35
  • 1
    You need to set `eax` to `1` before the `int 0x80` otherwise it's not going to be an exit system call. – Jester Nov 11 '21 at 14:36
  • I forgot to type the code but I do have the exit call before int 0x80 in actual code – SoHungry Nov 11 '21 at 14:57
  • No, you don't. Run `strace ./file` and/or single-step it with GDB. `int $0x80` needs a call number in EAX. You don't have `mov $__NR_exit, %eax` before the int $0x80. (It also has to be after the instructions that mess with the the low 2 bytes of EAX, AL and AH.) In future, always copy/paste your actual code, and use a code-formatting block (triple backticks). – Peter Cordes Nov 11 '21 at 15:00
  • 2
    @SoHungry Please post your actual code then. It is very difficult to diagnose problems with code that you have not posted or reproduced incorrectly or incompletely. [Edit] your question and add your actual code. – fuz Nov 11 '21 at 15:19

0 Answers0