Category:ARM Assembly: Difference between revisions
→Data Addressing using LDR and STR
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 46:
MyCode:
adr R2,RAM_Address ;get the address of a nearby place to store values.
MOV R0,#0x12345678
STR R0,[R2] ;store 0x12345678 into the first 32-bit slot.</lang>
Line 162:
===Limitations of the ARM===
While the ARM has a rich amount of features that other processors only dream of having, there are a few limitations.
The biggest one
Looking at the following in C and its ARM assembly equivalent (I've cut the stack twiddling and the return statement for clarity) we can see just what exactly happens:
<lang
return 0xFFFF;
}</lang>
<lang ARM Assembly>mov r0, #255 ;MOV R0,#0xFF
orr r0, r0, #65280 ;ORR R0,#0xFF00 (0xFF00|0x00FF = 0xFFFF)</lang>
It's very common to store "complicated" numbers into a nearby data block and just load from that data block with PC-relative addressing. These data blocks are usually placed after the nearest return statement so that they don't get executed as instructions.
<lang ARM Assembly>ldr r0,testData ;load 0xABCD1234 into R0
bx lr ;return
testData:
.long 0xABCD1234</lang>
Thankfully, there's an even easier solution than this. The GNU Assembler saves the day with the following special notation.
|