Addressing ModesInstructions handle data using one of the following addressing modes.
Register
Data is transferred between CPU registers.
Example:
mov a, b ; a=b coding: 1021
Immediate
A register is loaded with data submitted by the operand.
Example:
mvi a, 0x03ff ; a=03ff coding: 2081 03ff
Direct
Data is transferred between memory and a register. The address is given in the operand.
Example:
ld a, 0x4000 ; a=[4000] coding: 4891 4000
Indirect
Data is transferred between memory and a register. The address is given by another register used as a pointer.
Example:
ldx a, e ; a=[e] coding: 3591
Relative
It is possible to add a given value to the Program Counter (PC) to compute a jump relative to the current instruction; this is termed a "relative branch".
The relative addressing mode can in turn be direct (if the offset value is given by the operand) or indirect (if it is given by a register).
Examples:
jpr 0x0004 ; PC=PC+4 (Relative Direct) coding: 208b 0004
jprx e ; PC=PC+e (Relative Indirect) coding: 259b
Notice that the terms "direct" and "indirect" are not entirely appropriate since data has been given immediately and by a register respectively. However, since the data in question represents an address, we think that "direct" and "indirect" are more intuitive in this case.
Stack
Data is transferred between a register and a memory stack pointed by the Stack Pointer register (SP). Stack instructions are: PUSH and POP.
The Stack grows "backwards", that is, when a word is placed into the stack using the PUCH instruction, SP decrements pointing to the memory located just "above".
The Stack is normally "ready for insertion", that is a PUSH instruction will write first, then decrement the Stack Pointer. A POP instruction will increment SP first, then read.
|