Friday 21 June 2013

Moving registers to the data section

.global _start
.section .data
        value: .byte 42
.text
_start:
 ldr r1, =value
 mov r0, #9               @ r0 is now 9
 strb r0, [r1], #0        @ store the register r0 to the address in r1
 add r0, r0, r0           @ r0 is now 18
 ldrb    r0, [r1], #0     @ load the byte at address r1 to r0
 mov     r7, #1           @ set r7 to 1 - the syscall for exit
 swi     0                @ then invoke the syscall from linux


We initialise r0, and store it to memory, and then double the value of r0, and then read back from memory to r0.

Our return code (the value of r0) is the same as that stored rather than the doubled version.

By implication, our store and load were executed correctly.

If implication is suspicious, then it is possible to walk through the code using gdb to verify.

bob@poland:~/www/examples$ make movtest2
/usr/bin/as -gstabs -o movtest2.o movtest2.s
/usr/bin/ld -o movtest2 movtest2.o
bob@poland:~/www/examples$ ./movtest2 
bob@poland:~/www/examples$ echo $?
9
bob@poland:~/www/examples$

No comments:

Post a Comment