Thursday, 20 June 2013

Moving data from memory to a register

We use rodata (for read-only data).

# movtest1.s
@ An example of moving data from memory to a register
.global _start
.section .rodata
value: .byte 42
.align 2
.text
_start:
 ldr r1, =value
 ldrb r0, [r1], #1 @ load the byte at address r1 to r0 
                   @ r0 being the return value when we exit
 mov     r7, #1    @ set r7 to 1 - the syscall for exit
 swi     0         @ then invoke the syscall from linux

We use a makefile to build the software.

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

No comments:

Post a Comment