|
So before you can perform a computation with some value, you usually need to:
|
We will start learning how to move small integer values into registers.
Then we will learn how to move large (any) integer value into registers.
Next we will learn how to move values stored in memory variables into registers and vice versa.
mov rN, #x |
The value x will be stored as a 32 bit 2's complement number inside the register rN (X is any number between 0 and 10).
Examples:
mov r0, #4 // Stores 00000000000000000000000000000100 in r0 mov r0, #15 // Stores 00000000000000000000000000001111 in r0 |
How to run the program:
|
The format to encode the instruction to move the value x to register number dest is:
mov r0, #x is encoded in ARM as: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | |0|0|1|1|1|0|1|S|x|x|x|x| dest | value (x) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----> <-----> <-----> <---------------------> 1 1 1 0 "mov" not used 12 bits unconditional (S = 0 means: don't set the condition codes) (S = 1 means: set the condition codes according to the result of the operation) |
The mov instruction has only 12 bits to represent the value x.
Without going in the details on how the ARM processor uses these 12 bits to represent numeric values (it uses a very complicated method), you can deduce from the fact that:
|
|
Post postscript:
|
As a rule of thumb:
|
main: mov r0, #4 // Instr code: e3 a0 00 04 (4 is stored in binary!) mov r0, #15 // Instr code: e3 a0 00 0f (15 is stored in binary!) mov r1, #123456 // mov cannot handle very large values // Comment the above instruction to compile |
After assembly (= compiling), the assembler will generate the following machine instruction codes for the first 2 instructions:
Assembler instrcution Machine code ----------------------- -------------- mov r0, #4 --> 1110 0011 1010 0000 0000 0000 0000 0100 (e3 a0 00 04) mov r0, #15 --> 1110 0011 1010 0000 0000 0000 0000 1111 (e3 a0 00 0f) mov r0, #123456 --> Error: invalid constant (1e240) after fixup (123456 = 1e240 Hex) |
Observe that:
|
So as a rule of thumb:
|
Except that:
|
We will learn how to move larger values into a register next...