I just started learning ARM assembly. I am currently on a 32-bit Raspian with "GNU assembler version 2.35.2 (arm-linux-gnueabihf)".
This is my simple program to load part of ascii into a register :
.global _start
_start:
ldr r1,=helloworld
ldr r2,[r1]
@prepare to exit
mov r0,#0
mov r7,#1
svc 0
.data
helloworld:
.ascii "HelloWorld"
I loaded it into gdb and can see that my register r2 loads 0x6c6c6548 (in ascii "lleH"). A quick objdump shows :
Contents of section .data:
0000 48656c6c 6f576f72 6c64 HelloWorld
I have below questions :
- How does the string look like in memory? In other words, when the endianness come into picture? Will reversal happen while loading into memory? Or the string will be loaded as is into memory but gets reversed while loading into register?
- Why the content of register r2 for below program with
.wordis 0x12345678 instead of 0x78563412 ? Why there is no endianess followed?
Note : .word used instead of .ascii
.global _start
_start:
ldr r1,=helloworld
ldr r2,[r1]
mov r0,#0
mov r7,#1
svc 0
.data
helloworld:
.word 0x12345678
EDIT
The memory dump for first program shows that even the memory has string in same order as in the source code and the object file :
>>> x/32xb 0x1008c
0x1008c: 0x48 0x65 0x6c 0x6c 0x6f 0x57 0x6f 0x72
0x10094: 0x6c 0x64 0x41 0x11 0x00 0x00 0x00 0x61
This indicates that the ldr instruction is converting that memory read into little endian format where LSB holds the first byte in memory. Is the understanding correct? But this still does not answer why this did not happen for a .word.