1

I've toyed with the idea of learning an assembly language, and have decided to give ARM a try. I've decided to go with the GNU assembler, mostly because it's available in my cellphone's repository, so that I could play around with assembly anywhere, if I'm bored.

Anyway, I've searched the web, but I can't find any kind of reference for how to properly exit an ARM Linux binary. I've understood that the x86 equivalent basically sets the eax register to a number specifying the system call, and then calls system interrupt 0x80 to actually perform the system call, properly exiting the program; now I want to do something similar for ARM (and obviously the same code doesn't work, since it uses x86 specific registers and whatnot).

So yeah, basically, how would I write a minimal GAS ARM executable, simply exiting normally with exit value 0?

FireFly
  • 394
  • 4
  • 15
  • In most cases you can just return from the entry point (i.e. `BX LR` on ARM), the OS/loader should take care of shutting down the process. – Igor Skochinsky Feb 09 '12 at 12:23

2 Answers2

1

There is some information on system calls at http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=3105/4. You can also look at page 5 of http://isec.pl/papers/into_my_arms_dsls.pdf.

Jeremiah Willcock
  • 30,161
  • 7
  • 76
  • 78
0

teensy.s

.global _start
.thumb_func
_start:
    mov r0, #42
    mov r7, #1
    svc #0

Makefile

CROSS_COMPILE?=arm-linux-gnueabihf-

teensy:
    $(CROSS_COMPILE)as teensy.s -o teensy.o
    $(CROSS_COMPILE)ld teensy.o -o teensy
    ls -l teensy
    $(CROSS_COMPILE)objdump -d teensy.o
    $(CROSS_COMPILE)readelf -W -a teensy

clean:
    rm teensy teensy.o
auselen
  • 27,577
  • 7
  • 73
  • 114