EMAC PRIMER Instruction Manual page 45

Table of Contents

Advertisement

LESSON 13: Using Conditionals
NEW INSTRUCTIONS
JNZ
<addr> op code = C2
If the zero flag is 0, load the PC register with the two bytes following the op code, otherwise start
executing the instruction after this one. The first byte following the op code is the low byte of the address,
the second byte is the high byte of the address. No flags are affected.
The program below is the same as the one in Lesson 2 except that it provides a way to stop the program without pressing
the reset button.
leds
equ
dips
equ
org
loop:
in
out
ora
jnz
rst
end
The JNZ instruction is the same as the JMP instruction only it has a conditional (NZ) attached to it. Conditionals, in
general, control whether an instruction will be executed or whether it will be ignored. If the instruction is ignored, the
instruction following it will be executed. Not only the can the JMP instruction be controlled by conditionals but also the
CALL and RET instructions which are discussed.
Below is a list of the different jump instructions that use conditionals and the values of the flags that are necessary for the
jump to occur:
JNZ = Jump if result of operation was not 0
JZ
= Jump if result of operation was
JNC = Jump if no carry from the operation
JC
= Jump if the operation caused a carry
JPO = Jump if the parity of the result is odd
JPE = Jump if the parity of the result is even
JP
= Jump if a positive number result.
JM
= Jump if a negative number result.
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
Press the reset button and enter the program into memory. Now set the DIP switches to the off position so the value of the
DIP switches will not be zero. Run the program and it should work the same as the one in lesson 2, until the value of the
DIP switches are changed to zero. This happens when the DIP switches are moved to the on position and when this is
done, the program will execute the RST 7 instruction, return to the MOS and display "FF09 FF" which is the address and
the op code of the RST 7 instruction.
To analyze the program press the reset button and perform the following steps:
CURRENT PC
FF01
Move the DIP switches to the off position and single step to address FF06.
FF06
Examine the flag register and you will see that bit 6 (the zero flag) is 0 indicating that the ORA A
instruction did not give a zero as a result. ORing A with A will only give a 0 result if A equals 0 and as you
can see, A is not 0. Single step and the JNZ FF01 instruction will be executed because the conditional is
true (since zero flag is 0).
11h
12h
0ff01h
dips
; load the A register with DIP switch values
leds
; output the value to LEDs
a
; Set Z flag if A = 0
loop
; jump to loop if A not = 0
7
; return to MOS
DATA
INSTRUCTION
DB
IN
12
12
D3
OUT
11
11
B7
ORA
A
C2
JNZ
FF01
01
FF
FF
RST
7
0
45
(if Z
= 0)
(if Z
= 1)
(if CY = 0)
(if CY = 1)
(if P
= 0)
(if P
= 1)
(if S
= 0)
(if S
= 1)

Advertisement

Table of Contents
loading

Table of Contents