I'm trying to get into Assembly development for the purposes of better understanding lower level development and I'm doing this with my Raspberry Pi Model 4B. I am going through this tutorial at the moment but I wanted to try playing around a bit on my own. I created a really simple add assembly program like so:
.global main
main:
move r1, #4
move r2, #3
add r0, r1, r2
bx lr
I compiled and linked with the following:
as -o test.o test.s
gcc -o test test.o
and then ran ./test ; echo $?
and saw 7
as my output.
However when I modified my script to change the add line from add r0, r1, r2
to add r7, r1, r2
, I get a 1
as the output. It seems as though I get 1
as my output no matter what register I use but as I understand it the first 15 registers in an ArmV7 architecture as general purpose (with a couple exceptions) so the output register I use should be just fine here. Can someone explain why this returns 1
every time instead of the sum of registers 1 and 2?