|
|
|
I will discuss the encoding for the move instruction that store a value into the first register register r0 of the ARM processor - as a comparison to the same instruction in the M68000 processor
The documentation for the ARM's move instruction is on page 10 of the ARM instruction set document
mov r0, #x |
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 unconditional (S = 0 means: don't set the condition codes) (S = 1 means: set the condition codes according to the result of the operation) |
Here are some samples of the move instructions and their instruction codes:
// Instruction code mov r0, #1 // E3A00001 = 1110 0011 1010 0000 0000 0000 0000 0001 mov r5, #1 // E3A05001 = 1110 0011 1010 0101 0000 0000 0000 0001 mov r0, #127 // E3A0007F = 1110 0011 1010 0000 0000 0000 0111 1111 mov r0, #128 // E3A00080 = 1110 0011 1010 0000 0000 0000 1000 0000 mov r0, #129 // E3A00081 = 1110 0011 1010 0000 0000 0000 1000 0001 mov r0, #255 // E3A00FFF = 1110 0011 1010 0000 0000 0000 1111 1111 |
The interpretation of the first instruction code is as follows:
mov r0, #1 // E3A00001 = 1110 0011 1010 0000 0000 0000 0000 0001 When we put this bit pattern in the in the format of the mov instruction, you can identify the meaning of each bit easier: 1110 0011 1010 0000 0000 0000 0000 0001 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | |0|0|1|1|1|0|1|S|x|x|x|x| dest | value (x) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----> <-----> <-----> 1 1 1 0 "mov" not used unconditional |
You can see that the register r0 is encoded by the 4 bits register 0 0 0 0 in the middle of the instruction code.
The value 1 is encoded by the 12 bits 0 0 0 0 0 0 ... 0 1 at the end of the instruction code.
How to run the program:
|
mov r5, #1 // E3A05001 = 1110 0011 1010 0000 0101 0000 0000 0001 When we put this bit pattern in the in the format of the mov instruction, you can identify the meaning of each bit easier: 1110 0011 1010 0000 0101 0000 0000 0001 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | |0|0|1|1|1|0|1|S|x|x|x|x| dest | value (x) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----> <-----> <-----> 1 1 1 0 "mov" not used unconditional |
You can see that the register r5 is encoded by the 4 bits register 0 1 0 1 in the middle of the instruction code.
|
(Recall the M68000 processor has a longer but slower variant that can handle any value and a shorter variant that can be used for smaller values.
The ARM processor does not have the longer (= more complex) variant of the move instruction !!!)
|