EMAC PRIMER Instruction Manual page 47

Table of Contents

Advertisement

LESSON 14: Using Register Indirect Addressing
NEW INSTRUCTIONS
LXI
H,<word>
Load the HL register pair with the word (a word = 2 bytes) that follows the op code. The byte following the
op code goes in the L register and the byte after that goes into the H register. No flags are affected.
MVI
M,<byte>
Copy the byte that follows the op code to the byte in memory pointed to by the HL register pair. No
registers are affected.
MOV
E,M
Copy the byte in memory pointed to by the HL register pair to the E register. No flags are affected.
INX
H
Increment the value of the HL register pair. No flags are affected
MOV
M,E
Copy the E register to the byte in memory pointed to by the HL register pair. No registers are affected.
According to the definitions of MVI M,<byte>, MOV M,E and MOV E,M, the M referred to by these instruction works the
same way as a register, in that data can be loaded from it or stored to it, as bytes. But it is different than a register because
M refers to a certain location in memory. The HL register pair points to this memory location. Since the HL register pair is
16 bits it can point to any address in memory from 0000 to FFFF just as the PC register can.
For example, if HL had the value of 0131 hex and the MOV E,M instruction was executed, the data at memory
address 0131 will be copied to the E register. This is show below:
ADDRESS
:(addresses 0000-012F)
:
0130
0131
0132
0133
:
:(addresses 0134-FFFF)
The value loaded into E is the value of the byte pointed to by HL. If HL was 0133 then the value loaded into E would be
D8; If HL was 0132 then the value loaded into E would be CD and so on.
The MVI M,<byte> instruction works similarly, but instead of reading the byte pointed to by HL, it writes data to the byte
pointed to by HL. If HL was FFC3 and the MVI M,03 instruction was executed then 03 would be written to the data at
address FFC3. The value of the data at address FFC3 before and after the MVI M,03 instruction is shown below.
BEFORE
ADDRESS
:(addresses 0000-FFC0)
:
FFC1
FFC2
FFC3
FFC4
:
:(addresses FFC5-FFFF)
If the value of HL was changed to FFC1 and the MVI M,03 instruction was executed then the data at address FFC1 will be
changed to 03.
This method of accessing memory described in this lesson is called register indirect addressing. The following
program will copy a byte from one memory location to another and also store a value in memory illustrating the use of the
HL register pair to indirectly access memory.
op code = 21
op code = 36
op code = 7E
op code = 23
op code = 73
DATA
3C
01
<-HL
CD
D8
DATA
32
01
20 <-HL
14
AFTER
ADDRESS
:(addresses 0000-FFC0)
:
FFC1
FFC2
FFC3
FFC4
:
:(addresses FFC5-FFFF)
47
DATA
32
01
03 <-HL
14

Advertisement

Table of Contents
loading

Table of Contents