Category:ARM Assembly: Difference between revisions

no edit summary
(Added better examples.)
No edit summary
Line 61:
Most processors would have to push and pop the condition code register between the compare and the branch. Otherwise, the act of loading <code>r2</code> and <code>r3</code> would affect the outcome of the branch. Not so on the ARM!
 
 
===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 (which was more of an issue on earlier versions such as the ARM7TDMI CPU in the Game Boy Advance) is the limitation of the MOV command. Arguably the most important command any processor has (apart from JMP), the MOV command on the ARM is often limited in what can be loaded into a register in a single command. Depending on the pattern of bits, some immediate values cannot be loaded into a register directly. The key features of the ARM instructions (barrel shifter, conditional commands, etc) all take up bytes in each command, whether they are used in a given instance of a command or not. So in order to store 32 bit numbers in a MOV command, the value has to be "8-bit rotatable," meaning that it can be expressed as an 8 bit number if you shift it enough times. Basically if there are too many 1s in the binary equivalent of the number you're trying to load, it can't be done in one go.
 
Most of the time, this isn't a huge deal, as the easiest way around this is to define a data block nearby containing the value you wish to load. Since each command on the ARM takes 4 bytes of storage, this is guaranteed to take equal or fewer bytes than loading the number into a register piece-by-piece.
 
<lang ARM Assembly>
mov r0,#0x04000000
add r0,r0,#0x130
 
;compare to:
TestDataAddr: .word 0x04000130
ldr r0,TestDataAddr</lang>
 
Thankfully, there's an even easier solution than this. The GNU Assembler saves the day with the following special notation.
<lang ARM Assembly>mov r0, =#value</lang>
 
This isn't actually valid ARM code, it's more of a built-in macro. Essentially, the value will be loaded in one go as an immediate if it can. If not, it will get placed nearby as a data block and the <code>MOV</code> will be changed to an <code>LDR</code> command. Basically you can take everything in the above paragraph and forget about it, since equals notation does the work for you.
[[Category:Assembly]]
1,489

edits