Beruflich Dokumente
Kultur Dokumente
Lecture #4
Agenda Today
In all computer architectures, data must be moved into CPU registers for
processing (an input operation) and moved out of the registers after
processing (an output operation). The source and destination of the data
can be memory external from the CPU, I/O peripherals, or other CPU registers.
In the MSP430, the source and destination addressing mode is encoded in the
Instruction code—along with the opcode and register numbers.
1) Register Direct
• no operands are required, register only operations
2) Indexed
• operand provides fixed offset applied to address held in a CPU register
3) Register Indirect
• address is held in a CPU register – special case of indexed addressing
without operand
4) Register Indirect Autoincrement
• same as #3—but register is automatically incremented by 1 or 2
The first two can be used for both the source and destination and
the second two can be used only for the source.
mov.b R10,R11
• Moves the lower byte of the contents of 16-bit CPU register R10
to CPU register R11.
mov.w R10,R12
• Moves the entire 16-bit value stored in R10 to R12.
Both source and destination in this example use the register direct
addressing mode.
mov.b 1(R10),4(R11)
• R10 and R11 represent an address. A byte is fetched from
memory location R10+1 and copied to memory location R11+4.
mov.w 2(R10),4(R12)
• R10 and R12 represent an address. A word is fetched from
memory location R10+2 and copied to memory location R12+4.
mov.b @R10,R11
• Functionally the same as mov.b 0(R10),R11
• Moves the byte stored at memory location represented by R10 to
become the contents of R11.
mov.w @R10,R12
• 16-bit equivalent of the above.
Note the @ cannot be used for the destination. Register indirect is used
for the source and register direct is used for the destination in these
examples.
mov.b @R10+,R11
• Moves the contents of the memory location represented by the
contents of R10 into R11. After the copy operation, R10 is
incremented by 1 to “point” to the next byte in memory.
mov.w @R10+,R12
• 16-bit equivalent of the above. After the move, the contents of
R10 is incremented twice (by 2) to “point” to the next word in
memory.
Note that “register indirect autoincrement” can only be used for the
source and not the destination. The destination uses register
direct in these examples.
The four native addressing modes can be used in interesting ways (along
with the special behavior of the constant generators) to produce a few
more useful addressing modes (the first 3 mentioned below are
extensions of indexed addressing):
2. SP-Relative Addressing:
• The 16-bit fixed offset (operand) applied to the SP current value. Together
specifies the address of the data relative to the current SP value:
4. Immediate Addressing:
• The operand immediately following the instruction code is the raw data to
initialize a register or memory location to:
The assembler will allow use of these pseudo-addressing modes using special notation.
It will convert them into the appropriate native addressing mode for you.
Absolute Addressing:
mov.b &P1IN,R6 mov.b P1IN(SR),R6
– The absolute address of register “P1IN” is substituted in by assembler.
– Use ‘&’ symbol in front of variable names to specify the use of this addressing mode.
– Use for I/O in the lab. Typically this addressing mode is used to interact with on-chip
peripheral devices.
Immediate Addressing:
mov.w #1234,R7 mov.w @PC+,R7
– The immediate value 1234 is stored in the two bytes of memory immediately following the
instruction code.
– Use the # sign in front of a number to specify the use of this addressing mode.
Suppose I wanted to do two 16-bit loads from memory locations 0x0000 and
0x0002…
After a 16-bit load from 0x0000, I would see in CPU registers: 0x1234
After a 16-bit load from 0x0002, I would see in CPU registers: 0x5678
After a 16-bit load from 0x0000, I would see in CPU registers: 0x3412
After a 16-bit load from 0x0002, I would see in CPU registers: 0x7856
• Endian-ness applies to all memory accesses greater than 8-bits (i.e. 16-bit, 32-
bit, 64-bit, 128-bit)
• Generally speaking, higher-level programmers are insulated from these
architectural differences.
Ex) mov.w #0xABCD,R5 ; this instruction will put 0xABCD into register R5
mov.b #10101111b,R6 ; this instruction will put 10101111b into register R6
Ex) mov.w #0x0100,R5 ; initializes the R5 register to 0x0100 using immediate addressing
mov.w 2(R5),R6 ; loads register R6 with the contents of memory location 0x0102
; and 0x0103: Memory
0x0000 0x??
Mnemonics
0x0001 0x??
When referring to PC, SP, or SR, you may need to refer to them using their
true register names. Some assemblers may not know what they mean. Same
thing with CG1 and CG2.
See the chapter 5 (section 4) of the text book (don’t worry about
instructions we have not covered).