Reputation: 21
I am trying to write THUMB assembly code and I want to run it on Linux (x86). I can write ARM assembly and it works fine, but when compiling with the -mthumb option, nothing works. I can't find any tutorial online, so any resources would be great.
Here is the assembly code I am using :
.text
.globl _start
_start:
add r0, r0, $0
Here are the compilation options I am using :
arm-linux-gnueabihf-as -march=armv7-m -mcpu=cortex-m0 -mthumb -o main.o main.s
arm-linux-gnueabihf-ld -o main main.o
Here is how I try to run the binary :
LD_LIBRARY_PATH=/lib/arm-linux-gnueabihf qemu-arm main
Though, I did try to specify the CPU here as well (and also tried all sorts of combinations). I get the following error message :
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
Finally, using gdb-multiarch, all instructions are indeed shown as invalid (but I am unsure how to actually use gdb-multiarch, just followed a guide online).
I am obviously doing something wrong (whether it is the format of instructions or along with the compilation), I hope someone can clarify what is wrong and maybe give some online resources. Note that I don't have any issue with ARM/THUMB per se, I have been studying it for a bit, but never tried to write any code.
Upvotes: 1
Views: 351