Micro CH 4 Ex
Micro CH 4 Ex
2. The contents of memory locations 2400H, 2401H, 2402H and 2403H are 00, FFH, 0FH
and 1AH respectively. What will be the memory contents after the following instructions
are executed?
3. A value 05H is to be stored at memory locations 2000H, 2001H and 2002H. Write the
different programs to perform this. Select the program that will take the least amount of
memory and time to execute. Use only the instructions covered so far.
Solution:
MVI A, 05H
STA 2000H
STA 2001H
1
STA 2002H
Or:
MVI H, 05H
MVI L, 05H
SHLD 2000H
SHLD 2001H
Or:
LXI H, 2000H
MVI M, 05H
LXI H, 2001H
MVI M, 05H
LXI H, 2002H
MVI M, 05H
2- Arithmetic Instructions:
1. Five memory locations 2401H, 2402H, 2403H, 2404H, and 2405H have some data items
called X1, X2, X3, X4, and X5 respectively. Write a program to calculate and store in
different memory locations as in the following:
(2401H) = X1 + X5
(2402H) = X5 – X2
(2403H) = X4 + X1 + X3
(2404H) = X4 – X1 – X2
(2405H) = X1 + X2 + X3 + X4
Solution:
LXI H, 2401H
MOV B, M ; (B) = X1
LDA 2405H
ADD B
STA 2401H (or MOV M, A) → 1
INX H
2
MOV C, M ; (C) = X2
LDA 2405H
SUB C
MOV M, A → 2
INX H
MOV D, M ; (D) = X3
LDA 2404H
ADD B
ADD D
MOV M, A → 3
INX H
LDA 2404H (or MOV A, M)
SUB B
SUB C
MOV M, A → 4
INX H
LDA 2404H
ADD B
ADD C
ADD D
MOV M, A → 5
3- Logical Instructions:
1. Three numbers X1, X2 and X3 are stored at 2000H, 2001H and 2002H respectively.
Write programs to calculate Z1, Z2 and Z3 as per the following and store the result at
2100H, 2101H and 2102H respectively.
3
Z2 = (X1 + X3) XOR X2
Z3 = (X3 – X1) AND X2
Solution:
1) LDA 2000H
LHLD 2001H ; (L) = X2, (H) = X3
ORA L
ANA H
STA 2100H
2) LDA 2000H
LHLD 2001H ; (L) = X2, (H) = X3
ADD H
XRA L
STA 2101H
3) LDA 2002H
LHLD 2000H ; (L) = X1, (H) = X2
SUB L
ANA H
STA 2102H
3. What will be the values in registers A, H, L and locations 2400H, 2401H, 2500H and
2501H after the execution of the following instructions?
4
RLC ; (A) = 0CH
RLC ; (A) = 18H
RLC ; (A) = 30H
ANI. ..............98H ; (A) = 10H
4- Branch Instructions
5. Two numbers X and Y are stored in memory. Calculate the value of the expression (X +
Y – 100). If the value is negative, calculate the value of Z1 and store; otherwise, calculate
the value of Z2 and store in memory. The equations pertaining to Z1 and Z2 are as
follows:
Z 1 =X AND Y
Z 2 = X OR Y
Solution:
LDA 2000H ; (A) = X
LXI H, 2001H
MOV B, M ; (B) = Y
ADD B ; (A) = X+Y
SUI 64H (or CPI 64H)
J M Z1 ( or J C Z1)
LDA 2000H
ORA B
JMP END
Z1: LDA 2000H
ANA B
END: STA 2100H