Experiment 3
Experiment 3
AIM
THEORY
Arithmetic Instruction:
ADD; ADD Add the contents of a register
ADI; ADD Immediate Add 8-bit data.
The arithmetic instructions (except INR and DCR)
1. Assume implicitly that the accumulator is one of the operands
2. Modify all the flags according to the data conditions of the result
3. Place the result in the accumulator
4. Do not affect the contents of the operand register
The instruction INR and DCR
1. Affect the contents of the specified register
2. Affect all flag except the CY flag.
1
INR R Increment
This is a 1-byte instruction
Increases the contents of register R by 1
Caution: All flags except The CY are affected
DCR R Decrement
This is a 1-byte instruction
Decreases the contents of register R by 1
Caution: All flags except The CY are affected
Logical Instruction:
ANA; AND Logically AND the contents of a register
ANI; AND Immediate Logically AND 8-bit data
The logic instructions
1. Implicitly assume that the accumulator is one of the operands
2. Reset (clear) CY flag. The instruction CMA is an exception; it does not affect any flags.
3. Modify the Z, P, and S flag according to the data conditions of the result.
4. Place the result in the accumulator.
5. Do not affect the contents of the operand register.
2
ORI 8-bit OR Immediate with Accumulator (A)
This is a 2-byte instruction
Logically ORs the second byte with the contents of A
XRA R Logically Exclusive-OR with Accumulator (A)
This is a 1-byte instruction
Logically XORs the contents of the register R with the contents of A
XRI 8-bit Exclusive-OR Immediate with Accumulator (A)
This is a 2-byte instruction
Logically XORs the second byte with the contents of A
CMA Complement Accumulator
This is a 1-byte instruction that complement the contents of A
No flags are affected
3
3. Algorithm
Get two numbers
st
A. Load 1 no. in register D
nd
B. Load 2 no. in register E
Add them
A. Copy register E to A
B. Add register D to A
Store result
A. Copy A to register C
Stop
A. Stop processing
Start
st
A. Load 1 no. in register D
Load Registers D, E nd
B. Load 2 no. in register E
Copy E to A
A. Copy register E to A
B. Add register D to A
Add A and D
A. Stop processing
Stop
4
MOV A,E
ADD D
MOV C,A
HLT
Problem Statement 1: Add the contents of memory location 4001H and the contents of memory
location 2000H and place the result in memory location 4002H.
LXI H 4000H : HL points 4000H
MOV A, M : Get first operand
INX H : HL points 4001H
ADD M : Add second operand
INX H : HL points 4002H
MOV M, A : Store result at 4002H
HLT : Terminate program execution
Making Flow Chart
5
(4001H) = 89H
Result = 14H + 89H = _______H
Flag =
D7 D6 D5 D4 D3 D2 D1 D0
Problem Statement 2: Write a program to perform the following functions, and verify the
output.
1. Load the number 8BH in register D.
2. Load the number 6FH in register C.
3. Increment the contents of register C by one.
4. Add the contents of registers C and D and display the sum at the output PORT1.
Verification
6
QUESTION
A. Write a program to perform the following functions, and verify the output.
1. Load the number 8BH in register D.
2. Load the number 6FH in register C.
3. Increment the contents of register C by one.
4. Add the contents of registers C and D and display the sum at the output PORT 1.
7
C. Write a program using the ADI instruction to add the two hexadecimal numbers 3AH and
48 H and to display the answer at an output port.
D. Write instruction to
1. Load 00H in the accumulator
2. Decrement the accumulator
3. Display the answer
E. Write a program to
1. Clear the accumulator
2. Add 47H
8
3. Subtract 92H
4. Add 64 H
5. Display the results after subtracting 92H and after adding 64H.