Chapter 3: Addressing modes Flashcards
Why do we need addressing modes?
Each instruction in a particular instruction set requires operands but there are different ways that these operands can be specified.
The simplest operands?
In the simplest case, the operands are implicit or implied by the instruction itself.
CLRF 10
What is an offset?
“Relative addressing uses a base address stored in a register plus an offset or index to get the data address. This method is good for addressing an array of data. In this case the base address will be the first element of the array, and incrementing the offset will access the next elements. The offset can either be specified within the instruction or contained in another register.”
What are implicit or implied
specified. In the simplest case, the operands are implicit or implied by the instruction itself. For example:
The PIC instruction CLRF 10 sets the register at address 10 to zero The 6502 instruction CLC clears the carry flag. The use of the status register address, which contains that carry bit, is implied by that command
What is immediate or literal addressing?
These are operands that have been specified in the instruction themselves.
Problems with literal or immediate addressing?
However the space available for the operand in the address might not be large enough to fill the memory destination. In some cases the operand might be sign or zero extended as discussed before. In others, registers can be loaded half at a time.
Example of a immediate or literal or addressing?
movlw H’FF’ (movlw = move literal to the working register)
What is Direct or absolute addressing?
- Direct or absolute addressing is where the address of the operand is specified in the instruction.
- The address might correspond to a register or a memory address. When registers are involved, this addressing mode is called register or register direct addressing.
What is direct or absolute addressing where registers are involved?
When registers are involved, this addressing mode is called register or register direct addressing.
Example if direct/absolute addressing
movf H’05’
(movf = move data at f to the working register)
This moves the data stored at the file register with hexadecimal address 05 to the working register.
What is indirect addressing?
- The indirect addressing mode is where the instruction specifies the memory location where the address of the required data is being kept.
- This is sometimes called a pointer. Therefore the location of the ‘pointer’ is constant, but the location of the data to which the pointer is pointing may change.
Indirect addressing: What happens when a register contains a pointer?
When a register contains the pointer, this is called the register indirect addressing mode.
Example of indirect addressing?
The PIC16F84A has its own indirect addressing scheme. The FSR (file select register) is a pointer to the memory address that it contains. By using INDF as one of the operands in an instruction such as an add, the control unit will fetch the data at the address specified in the FSR register.
- movlw H’12’ move Ox12 to the working register
- movwf FSR move W to the File Select Register
- movlw D’05’ move 5 to the working register
- addwf INDF add W to register pointed at by FSR (i.e:0x12)
This moves the literal value into the FSR register so that the addwf instruction adds together the value 5 in the working register with the data at memory address 0x12.
What is relative addressing?
Relative addressing uses a base address stored in a register plus an offset or index to get the data address. This method is good for addressing an array of data. In this case the base address will be the first element of the array, and incrementing the offset will access the next elements. The offset can either be specified within the instruction or contained in another register. Sometimes an index can be scaled to take into account the number of addresses each piece of data covers