Review 1: Instructions are stored in RAM (memory)
Review 2: The CPU fetches instructions into its Instruction Register first:
The fetched instruction is then executed (by steps 2,3,4 of the instruction execution cycle)
Important fact about
assembler programming:
|
We will study the data transfer instructions:
|
The first way to use the mov instruction:
|
Examples:
mov r0, #15 // Stores 00000000000000000000000000001111 in r0 mov r1, #-15 // Stores 11111111111111111111111111110001 in r1 |
Effect of the mov instructions:
DEMO: home/cs255001/demo/asm/2-mov/mov-intro.s
Also try: mov r0, #123456 (1e240(16) = 12345610)
Suppose the next instruction executed is mov r0, #15:
The mov r0, #15 instruction is first fetched into the Instruction Register (IR) by the Instruction Fetch step
Then the mov r0, #15 will be executed by steps 2,3,4 of the Instruction Execution Cylce:
The mov r0, #15 will store the (binary) number 15 (= 00..1111) into register R0
The mov instruction is encoded as follows:
mov rN, #x is encoded in ARM as: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | |0|0|1|1|1|0|1|S|x|x|x|x| N | value (x) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----> ^ <-----> <-----> <---------------------> 1 1 1 0 | "mov" not used 12 bits unconditional | immediate bit (= use x as a number) |
Notice: there are only 12 bits available in the instruction code to encode the value x !!!
Therefore:
|
Simplified rule for using mov rN, #x:
|
Comment:
|
For the curious: you can read the online lecture note for the explanation: click here )
|