EMAC PRIMER Instruction Manual page 71

Table of Contents

Advertisement

LESSON 24: Using Compare Instructions
NEW INSTRUCTIONS
RLC
Shift the bits in the A register to the left and put the value shifted out of bit 7 in the carry flag and bit 0.
Only the carry flag is affected.
CMP
L
Subtract the L register from the A register and set the condition flags accordingly without changing the A
register. The carry flag is 1 if A < L and the zero flag is 1 if A = L. The Z,S,P,CY and AC flags are
affected.
CPI
<byte> op code = FE
Subtract the byte following the op code from the A register and set the condition flags accordingly without
changing the A register. The carry flag is 1 if A < byte and the zero flag is 1 if A = byte. The Z,S,P,CY
and AC flags are affected.
This program demonstrates the compare instructions CPI and CMP. Both compare instructions subtract a value from the A
register and set the flags accordingly, without changing the A register. If the value subtracted from the A register is equal to
the A register then the zero flag is made 1, if it is not equal then the zero flag is made 0. This program reads the value of
the keypad and changes the pattern displayed on the digital output LEDs depending on whether the key pressed was "3"
or "0". If any other key is pressed the display is not changed.
leds
equ
keyin
equ
mos
equ
org
mvi
loop:
mov
out
mvi
call
mvi
cmp
jnz
mov
rlc
mov
check3:
mov
cpi
jnz
mov
rrc
mov
jmp
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
FF09
FF0A
FF0B
FF0C
FF0D
continued on next page...
op code = 07
op code = BD
11h
; port for discrete LEDs
0bh
; service number for keyin
1000h
; address of MOS services
0ff01h
; start program at FF01
b,11110111b ; bit pattern for 1 LED lit
a,b
; A = bit pattern in B
leds
; display bit pattern
c,keyin
; c= keyin service number
mos
; return a key value in L
a,0
; value for "0" key
l
; compare A with L
check3
; jump if L<>A,(key isn't "0")
a,b
; A is the bit pattern
; rotate the bits in A left
b,a
; save pattern in B
a,l
; A = key value from keyin service
3
; compare A with "3" key value
loop
; jump if A<>3 (key isn't "3")
a,b
; A is the bit pattern in B
; rotate A right
b,a
; put new bit pattern in B
loop
; display new bit pattern
DATA
INSTRUCTION
06
MVI
B,F7
F7
78
MOV
A,B
D3
OUT
11
11
0E
MVI
C,0B
0B
CD
CALL 1000
00
10
3E
MVI
A,0
00
BD
CMP
L
71

Advertisement

Table of Contents
loading

Table of Contents