EMAC PRIMER Instruction Manual page 51

Table of Contents

Advertisement

LESSON 16: Using Register Indirect Addressing to Move Data
NEW INSTRUCTIONS
INX
B
Increment the BC register pair. No flags are affected.
INX
D
Increment the DE register pair. No flags are affected.
DCR
L
Decrement the L register. Z,S,P and AC flags are affected.
LDAX B
Copy the byte from the memory location pointed to by the BC register pair to the A register. No flags are
affected.
STAX D
Copy the A register to the byte in memory pointed to by the DE register pair. No flags are affected.
The program below uses indirect addressing to copy a series of bytes from one memory location to another.
Copying blocks of data from one memory location to another is done quite often in word processor programs and programs
that use graphics, such as video games. For this program the BC register must be loaded with the address of the start of
the memory block to move, DE must be loaded with the address (a RAM address) to which you want to copy the memory
block and L must be loaded with the number of bytes in the block that you want to copy.
org
loop:
ldax
stax
inx
inx
dcr
jnz
rst
db
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
FF0A
FF0B
After entering the program into memory, press reset and load BC with FF03, load DE with FF0A, load HL with 0002 and do
the following:
CURRENT PC
FF01
Single step and the A register will be loaded with the value of the byte pointed to by the BC register pair (the byte
at FF03 is 03).
FF02
Single step and the A register will be stored at the memory address pointed to by the DE register pair (FF0A).
FF03
Single step and the BC register pair will be incremented so that it points to the next memory address (FF04) from
which to get data.
op code = 03
op code = 13
op code = 2D
op code = 0A
op code = 12
0ff01h
b
; load A with byte pointed to by BC
d
; store A at address in DE
b
; increment BC.
; next address from which to get a byte.
d
; increment DE.
; next address to store a byte.
l
; decrement L
loop
; if L is not 0, then loop again
7
; return to MOS
0,0
; make these bytes 0 so we can see they have changed
DATA
INSTRUCTION
0A
LDAX B
12
STAX D
03
INX
B
13
INX
D
2D
DCR
L
C2
JNZ
FF01
01
FF
FF
RST
7
00
(data, not an instruction)
00
(data also)
This points BC to the
This points DE to the
51

Advertisement

Table of Contents
loading

Table of Contents