EMAC PRIMER Instruction Manual page 52

Table of Contents

Advertisement

FF04
Single step and the DE register pair will be incremented so that it points to the next memory address (FF0B) to
store data.
FF05
Single step and the L register will be decremented. Since the result is not 0, the zero flag is 0.
FF06
Single step and JNZ FF01 will load PC with FF01 since the zero flag is 0.
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 FF04 is 13).
FF02
Single step and the A register will be stored at the memory address pointed to by the DE register pair (FF0B).
FF03
Single step and the BC register pair will incremented so that it points to the next memory address (FF05) from
which to get data.
FF04
Single step and the DE register pair will incremented so that it points to the next memory address (FF0C) to store
data.
FF05
Single step and the L register will be decremented and since the L register has been decremented to 0 the zero
flag has been set.
FF06
Single step and since the zero flag is 1 the PC register will be loaded with FF09 which is the address of the
instruction following the JNZ FF01 instruction.
FF09
This is the end of the program. Press "enter" and you will see that the byte at FF03 has been copied to memory
address FF0A; Press enter again and you will see that the byte at FF04 has been copied to memory address
FF0B.
Press reset, load BC with FF01 and load DE with FF0A as before, but this time load HL with 0009 and run the program.
Running the program will make another copy of the program beginning at address FF0A. Examine the memory from FF0A
to FF12 and you will see that it matches the memory from FF01 to FF09. You can also experiment with different values for
BC, DE and L, but be careful in your choice of values for DE and L because some values will cause the program to destroy
itself by writing data in addresses FF01 to FF09.
This program uses what is called "conditional looping". Conditional looping causes an instruction or group of instructions to
be repeated as long as a certain condition becomes true. The instructions that are repeated in this program are LDAX B,
STAX D, INX B, INX D and DCR L and the condition that must be true is that the L register must not be zero. You noticed
that when the program was run, the L register was 2 and the instructions were executed 2 times. So you see that the value
of L determines the number of times that the instructions will be executed. The way this works is the DCR L instruction
decrements the L register and sets the zero flag if the L register is now zero and the JNZ FF01 will jump to the first
instruction as long as the L register is not 0. If the L register is 0 before the DCR L instruction is executed the latter will
cause the L register to be changed to FF hex and the instructions will be repeated 256 times.
52

Advertisement

Table of Contents
loading

Table of Contents