EMAC PRIMER Instruction Manual page 43

Table of Contents

Advertisement

LESSON 12: Using Logic Instructions
NEW INSTRUCTIONS
ANI
<byte> op code = E6
Logically AND the A register with the byte following the op code and store the result in the A register. The
Z,S,P,CY and AC flags are affected.
XRI
<byte> op code = EE
Logically XOR the A register with the byte following the op code and store the result in the A register. The
Z,S,P,CY and AC flags are affected.
ORI
<byte> op code = F6
Logically OR the A register with the byte following the op code and store the result in the A register. The
Z,S,P,CY and AC flags are affected.
Sometimes it is desired to change bits of a register to different values. Examine the result of the ANI instruction.
10010010
ANI
11000011
10000010
If there is a 0 in a bit position in <byte> then the corresponding bit in the result will be 0. If there is a 1 in a bit position in
<byte> then the corresponding bit in the A register will be copied to the result. Knowing this, the AND operation would be
useful in a program where you needed to check the status of an input port bit. The way this is done is illustrated below.
The A register holds the value of the input port, and <byte> has a bit set which corresponds to the one you want to examine
and all other bits are 0.
00101111
ANI
00100000
00100000
All bits in the value of the input port have been made 0 except that the bit that we wanted to examine is 1. According to the
logic of the AND operation, all bits would have been 0 if the input port bit 5 was off. This method of making certain bits 0
and passing other bits is called "masking" and the data that is ANDed to the A register is called the "mask".
In the situation where it is needed to change bits to 1, the OR operation should be used. As seen below, a bit value in A is
copied to the result if the corresponding bit value in <byte> is 0, and a bit is set to 1 in the result if the corresponding bit
value in <byte> is 1 .
01000011 (A register)
ORI
10101110 (<byte>)
11101111 (result)
To complement or toggle particular bits (change 1s to 0s and 0s to 1s), the XOR operation can be used.
10101011 (A register)
XRI
11110000 (<byte>)
01011011 (result)
If a bit in <byte> is 1 then the corresponding bit in A will be toggled in the result, otherwise if it is 0 the corresponding bit in
A will be passed to the result unchanged.
The following program combines the instructions ANI, ORI and XRI to change the data from input port B
(connected to the DIP switches) by setting, resetting and toggling the bits. This process of changing bits is called "bit
manipulation". Bit manipulation instructions are used by the MOS to allow the 8085 to control other chips in the PRIMER
and to read data from them.
(A register)
(<byte>)
(result)
(input port value)
(examine bit 5)
(result)
43

Advertisement

Table of Contents
loading

Table of Contents