1
votes

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?

2
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

2 Answers

0
votes

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