Course on Microprocessor Theory and Interfacing. This is fifth lecture on logical group of instructions of 8085 microprocessor. This lecture has a all logical instructions along with solved examples
1. Presented by:
Engr Zeeshan Ahmed Lodro
Lecturer-Department of Electronics Engineering Technology
BBS University of Technology and Skill Development Khairpur Mirs
1
Lecture-04
3. Instructions to perform AND operation
Instruction type ANA R
Instruction type ANI d8
Instructions to perform OR operation
Instruction type OR A
Instruction type ORI d8
Instructions to perform Exclusive OR operation
Instruction type XRA R
Instruction type XRI d8
3
4. Instructions to complement accumulator
Instructions to complement/set cy flag
Instruction type CMC
Instruction type STC
Instructions to perform compare operation
Instruction type CMP R
Instruction type CPI d8
Instructions to rotate accumulator
Instruction type RLC
Instruction type RAL
4
5. In operations likeAND , which need two
operands, 8085 imposes the restriction that
one of the operands must be in the
accumulator.The other operand can be one
of the following.
Contents of 8-bit register
Contents of memory location pointed by HL
register pair.
Eight bit immediate data.
5
6. The AND operation performs bit wise AND of
the two operands. If X is a bot of accumulator,
andY is a bit of the other operand in the same
bit position.The and operation is performed
as per following.
6
7. The AND instruction affects the following
flags:
S,P and Z flags are updated based on the
result.
Cy flag is reset to o;
AC flag is set to 1.
7
8. ANA is a mnemonic which stands for And
Accumulator and R stands for any of the 8085
registers.
This instruction is used to AND contents of R
with accumulator.The result of AND
operation will be stored in accumulator.
8
9. ANA E
The result of execution is shown below
Summary:
ANA R( 1-byte; ANA E; 8 opcodes)
9
Register Before After
E 45H
A 33H 01H
F Any values Cy= 0, AC=1,
S=0,P=0
10. ANI is a mnemonic that stands for And
Immediate with Accumulator and d8 stands
for any 8-bit data.This instruction is used to
AN 8-bit immediate data with the
accumulator,The result of ANDing will be
stored in the Accumulator,
The S,P and Z flag are affected based on the
results.
10
11. ANI F3H
The result of execution is shown below
Summary:
ANI d8 ( 2-bytes; ANI F3H; 1 opcodes)
11
Register Before After
A 45H 41H
F Any values Cy= 0, AC=1,
S=0,P=1, Z=0
13. The OR operation performs bit-wiseOR of
the two operands.The OR operation is
performed as per following table.
13
14. ORA is mnemonic that stands for OR
Accumulator and R stands for any of the 8085
registers.
This instruction is used to OR contents of R
with the accumulator.The result of OR
operation will be stored in the Accumulator.
14
15. ORA E
The result of execution is shown below
Summary:
ORA R ( 1-byte; ORA E; 8 opcodes)
15
Register Before After
E 45H
A 33H 77H
F Any values Cy= 0, AC=0,
S=0,P=1, Z=0
16. ORI is a mnemonic that stands for OR
Immediate with Accumulator and d8 stands
for any 8-bit data.
This instruction is used to OR 8-bit
immediate data with the accumulator.
The result of Oring will be stored in the
Accumulator.
16
17. ORI F3H
The result of execution is shown below
Summary:
ORI d8 ( 2-bytes; ORI F3H; 1 opcode)
17
Register Before After
A 45H F7H
F Any values Cy= 0, AC=0,
S=1,P=0, Z=0
19. XRA is a mnemonic that stands for eXclusive
OR accumulator and R stands for any of the
following registers or memory location
pointed by HL pair.
This instruction is used to EX-OR contents of
R with the accumulator,The result of EX-OR
operation will be stored in the Accumulator,.
19
20. XRA E
The result of execution is shown below
Summary:
XRA R ( 1-byte; XRA E; 8 opcodes)
20
Register Before After
E 45H
A 33H 76H
F Any values Cy= 0, AC=0,
S=0,P=0, Z=0
21. XRI is a mnemonic that stands for eXclusive
OR immediate with Accumulator and d8
stands for 8-bit data.
This instruction is used to Ex-OR 8-bit
immediate data with the accumulator.
The result of EX-oring will be stored in
accumulator.
21
22. XRI F3H
The result of execution is shown below
Summary:
XRI d8 ( 2-bytes; XRI F3H; 1 opcode)
22
Register Before After
A 45H B6H
F Any values Cy= 0, AC=0,
S=1,P=0, Z=0
23. The complement instruction in 8085 has the
mnemonic CMA that stands for CoMplement
the Accumulator.
It performs 1s complement operation on the
contents of accumulator and the result is
stored back in the accumulator.
Note that only accumulator contents can be
complemented but not others.
23
24. CMA
The result of execution is shown below
Summary:
CMA( 1-byte; CMA; 1 opcode)
24
Register Before After
A 45H BAH
25. Intel 8085 provides instructions to
complement Cy flag, and set the CY flag to
the 1 state, but it does not have an instruction
to reset the Cy flag to 0.
If it is desired to reset Cy flag to 0, the
method is to set 1 and then complement it.
25
26. CMC stands for CoMplement the Carry flag.
it performs complement operation on the Cy
flag and the result is stored back in the CY
flag.
26
27. CMC
The result of execution is shown below
Summary:
CMC( 1-byte; CMC; 1 opcode)
27
Register Before After
Cy 1 0
28. STC stands for SeT the Carry flag.
It sets the Cy flag to the 1 state.
Immaterial of its earlier value.
28
29. STC
The result of execution is shown below
Summary:
STC( 1-byte; STC; 1 opcode)
29
Register Before After
Cy 1 1
Register Before After
Cy 0 1
30. A compare instruction compares two
operands, and affects the status flags values
depending on the result of the comparison.
In this operation, 8085 imposes the
restriction that one of the operands must be
in the accumulator and the other operand can
be of the following.
Contents of 8-bit register
Contents of memory location pointed by HL pair.
Eight bit immediate data.
30
31. The compare instruction actually computes the value of
the accumulator contents minus other operand.
The original values of the operand are not changed.
The result is stored in the register that is not accessible
to the programmer.
Based on the results , all the flags are affected.
It is very similar to comparing the heights of two
persons. After comparison heights remains unaltered
but we reach at some conclusions like.
Both are of same height.
Person 1 is taller
Person 2 is shorter.
31
32. CMP is a mnemonic that stands for CoMPare
accumulator and R stands for any of the
following registers.
R=A,B,C,D,E,H,L,or M
This instruction is used to compare contents
of the accumulator with R.The result of
compare operation will be stored in theTemp
register.Temp is an internal register that is
not accessible to the programmer.
32
33. CMP E
The result of execution is shown below
Summary:
Summary:
CMP R( 1-byte; CMP E; 8 opcodes)
33
Register Before After
A F5H
E 25H
Temp 45H D0H
F AnyValues Cy=0, AC=1, Z=0,
P=0, S=1
34. Convert accumulator value F5 into binary
Convert E register value 25 into binary
Perform subtraction and convert result back into hex.
1111 0101
0010 0101
1101 0000
Cy=0 because carry not generated
AC=1 because of assistance during BCD operations or
undefined behavior(no any solid reason) or AC=1 always
Z=0 because result is not zero
P=1 because result has even number of 1s
S=1 because result is negative.There are two ways to
check in binary if the MSB is 1 result is negative and in hex
if left most digit is in range 8-F the result is negative.
34
35. CMP E
The result of execution is shown below
Summary:
Summary:
CMP R( 1-byte; CMP E; 8 opcodes)
35
Register Before After
A 50H
E 70H
Temp 45H E0H
F AnyValues Cy=1, AC=1, Z=0,
P=0, S=1
36. Convert 50 into binary and also convert 70
into binary then subtract 70 from 50 and get
result E0
0101 0000
0111 0000
1110 0000
E0
36
37. CMP E
The result of execution is shown below
Summary:
Summary:
CMP R( 1-byte; CMP E; 8 opcodes)
37
Register Before After
A 50H
E 50H
Temp 45H ??
F AnyValues Cy=0, AC=1, Z=1,
P=1, S=0
38. CMP E
The result of execution is shown below
Summary:
Summary:
CMP R( 1-byte; CMP E; 8 opcodes)
38
Register Before After
A F5H
E D5H
Temp 45H ??
F AnyValues Cy=0, AC=1, Z=0,
P=0, S=0
39. CMP E
The result of execution is shown below
Summary:
Summary:
CMP R( 1-byte; CMP E; 8 opcodes)
39
Register Before After
A 25H
E F5H
Temp 45H ??
F AnyValues Cy=1, AC=1, Z=0,
P=0, S=1
40. CPI is a mnemonic that stand for Compare
Immediate with Accumulator and d8 stands
for any 8-bit data.
This instruction is used to compare
accumulator with 8-bit immediate data.
The result of the comparison is not accessible
to the programmer.
All the flags are affected based on the results.
40
41. CPI F5H
The result of execution is shown below
Summary:
CPI d8( 2-bytes; CPI F5H; 1 opcode)
41
Register Before After
A 25H
Temp 45H 30H
F AnyValues Cy=1, AC=1, Z=0,
P=1, S=0
42. Intel 8085 provides instructions to rotate the
accumulator contents from left to right.
Rotate operation can be performed only on
accumulator.
42
43. RLC stands for Rotate Left accumulator. It
rotates the accumulator contents to the left
by 1-bit position.
Rotate left without involving cy in rotation
43
44. It can be seen ,after rotate left operation, the bit
that moves out from the MS bit position goes to
vacancy created in the LS bit position.
Also Cy flag gets a copy of the bit moved out
from the MS bit position.
Notice that CY flag is not involved in the rotation
and it is only 8-bit rotation of accumulator
contents.
Only Cy flag is affected by this instruction
execution.
44
45. To check the value of MS bit of accumulator ,
perform rotate left and note the cy flag value
To perform multiplication by 2, rotate
accumulator to left. It works correctly for
unsigned numbers as long as the MS bit of
accumulator before rotation is 0.
45
46. Note that Accumulator’s MSB value before rotation was 0 so result
is doubled.
Note that Accumulator’s MSB value before rotation was 1 so result is
not doubled.
46
Register Before After
A 24H 48H
Cy 1 0
Register Before After
A 84H 09H
Cy 0 1
47. RAL stands for rotate accumulator left
involving Cy flag in rotation. It rotates the
accumulator contents to the left by 1-bit
position.
Rotate left involving carry
47
48. It can be seen that after rotate left operation,
the bit moves out from the MS bit position
and goes to the Cy flag and in the process
moves out earlier carry bit to the vacancy
created in the LS bit position.
Notice that Cy flag is involved in the rotation
and it is 9 bit rotation of accumulator and Cy
contents.
Only Cy flag is affected by this instruction
execution.
48
49. To check the value of the MS bit of accumulator,
perform rotate left and note the Cy flag value.
To perform the multiplication by 2, rotate the
accumulator to the left, it works correctly for
unsigned numbers as long as the MS bit of
accumulator and Cy flag are 0 before rotation.
For multiplication by 2^n perform rotate left n
times.
To introduce a new bit value to the LS bit
position, put this bit value in the Cy flag and then
execute this instruction.
49
50. Note that Accumulator is doubled.
Note that Accumulator’s value is not doubled in this case because
MS bit of accumulator was a 1 before rotation.
50
Register Before After
A 24H 48H
Cy 0 0
Register Before After
A 84H 08H
Cy 0 1