|
In order to move a large binary number (that requires more bits to encode), we break the binary number into 2 (equal) halves:
<------------- large binary number ----------->
+-----------------------+-----------------------+
| most significant bits | least signficant bits |
+-----------------------+-----------------------+
|
And use 2 assembler instructions:
|
These pair of assembler instructions must be use in this order:
movw rN, #lower16bits
movt rN, #upper16bits
|
because the movw instruction will clear the upper 16 bits in the destination register rN.
main:
movw r0, #1 // Move 0000000000000001 into the lower half of r1
movt r0, #1 // Move 0000000000000001 into the upper half of r1
// The result is: 00000000000000010000000000000001
// which represents the value 65536 (decimal)
|
After the execution of the movw r0, #1 instruction, the registerr0 of the ARM processor will contain:
<----------- register r0 ---------->
+------------------+------------------+
| 0000000000000000 | 0000000000000001 |
+------------------+------------------+
|
And after the execution of the (next) movt r0, #1 instruction, the registerr0 of the ARM processor will contain:
<----------- register r0 ---------->
+------------------+------------------+
| 0000000000000001 | 0000000000000001 |
+------------------+------------------+
|
When you read the value in register r0 as a 32 bit (binary) number, the value that this binary number represents is:
00000000000000010000000000000001 (binary) = 65537 (decimal)
|
That means:
|
How to run the program:
|
This is obviously a problem for a human programmer that is not used to calculation in binary
Do not worry, the ASM assembler has provide 2 helpful operations to assist you.
#:lower16:x ≡ the lower 16 bits of the number x
#:upper16:x ≡ the upper 16 bits of the number x
|
Let me demonstrate it with an example:
|
How to run the program:
|