Programming For Learners 8085
Programming For Learners 8085
Solutions
1. MVI A, 52H : Store 32H in the accumulator
STA 4000H : Copy accumulator contents at address 4000H
HLT : Terminate program execution
2.
LDA 2000H
MOV B, A
LDA 4000H
STA 2000H
MOV A, B
STA 4000H
Q3.
LHLD 4000H
XCHG
LHLD 4002H
MOV A, E
ADD L
MOV L, A
MOV A, D
ADC H
MOV H, A
SHLD 4004H
HLT
4. Statement: Add the contents of memory locations 4000H and 4001H and place the result
in the memory locations 4002Hand 4003H.
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 the lower byte of result at 4002H
MVIA, 00 :Initialize higher byte result with 00H
ADC A :Add carry in the high byte result
INX H :HL Points 4003H
MOV M, A :Store the higher byte of result at 4003H
4. LHLD 4000H
XCHG
LHLD 4002H
MOV A, E
SUB L
MOV L, A
MOV A, D
SBB H
MOV H, A
4005H.
SHLD 4004H
4005H.
HLT
5. LDA 4200H
CMA
ADI, 01 H
STA 4300H
HLT
MOV A, C
RAR
RAR
RAR
RAR
MOV C, A
HLT
9. Statement: Write a program to count number of ls in the contents of D
register and store the count in the B register
MVI B, 00H
MVI C, 08H
MOV A, D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
HLT
10. Write a program to sort given 10 numbers from memory location 2200H in
the ascending order.
LDA 2200H
MOV C, A : Initialize counter
MVI B, 00H : sum = 0
LXI H, 2201H : Initialize pointer
BACK: MOV A, M : Get the number
ANI 0lH : Mask Bit l to Bit7
JNZ SKIP : Dont add if number is ODD
MOV A, B : Get the sum
ADD M : SUM = SUM + data
MOV B, A : Store result in B register
LDA 2200H
MOV C, A : Initialize counter
LXI H, 2201H : Initialize pointer
MVI E, 00 : Sum low = 0
MOV D, E : Sum high = 0
BACK: MOV A, M : Get the number
ANI 0lH : Mask Bit 1 to Bit7
JZ SKIP : Dont add if number is even
MOV A, E : Get the lower byte of sum
ADD M : Sum = sum + data
MOV E, A : Store result in E register
JNC SKIP
INR D : Add carry to MSB of SUM
SKIP: INX H : Increment pointer