Old Question Solution 8085 Program
Old Question Solution 8085 Program
1. Write a program in 8085 to find the largest and smallest bytes from the list of 20 bytes stored starting from
memory location C050H. Store the largest byte and smallest byte in C070H and C071H respectively. (8)
[2076 BAISAKH]
Solution:
LXI H,C050H
MVI C,13H
MOV E,M
MOV D,M
NEXT:INX H
MOV A,E
CMP M
JNC SKIP1
MOV E,M
CMP M
JC SKIP2
MOV D,M
SKIP2: DCR C
JNZ NEXT
XCHG
SHLD C070H
HLT
Solution:
LXI H,C050H
MVI C,32H
MVI D,00H
NEXT:MOV A,M
ANI 0FH
MOV B,A
MOV A,M
ANI F0H
RLC
RLC
RLC
RLC
CMP B
JC SKIP
JZ SKIP
INR D
SKIP: INX H
DCR C
JNZ NEXT
MOV A,D
STA CO82H
HLT
Solution:
Hint:
To interchange D1 and D4 in each data byte
Data Byte: D7 D6 D5 D4 D3 D2 D1 D0
ANDing by: 0 0 0 1 0 0 1 0 = 12H to check D4 and D1 bit
Possible result: 0 0 0 0 0 0 0 0 = 00H (if D1=0 & D4=0 no need to interchange)
0 0 0 0 0 0 1 0 = 02H (if D1=1 & D4=0 complement both bits for interchange)
0 0 0 1 0 0 0 0 = 10H (if D1=0 & D4=1 complement both bits for interchange)
0 0 0 1 0 0 1 0 = 12H (if D1=1 and D4=1 no need to interchange)
Program:
LXI H,9000H
LXI B,9040H
LXI D,9060H
L3:PUSH H
MOV A,L
ADI 20H
MOV L,A
MOV A,M
POP H
ADD M
STAX B
JNC L1
MVI A,01H
JMP L2
L1:MVI A,00H
L2:STAX D
INX B
INX D
INX H
MOV A,E
CPI 74H
JC L3
HLT
Solution:
LXI H,9000H
MVI D,0AH
MVI B,00H
MOV A,M
NEXT: RLC
JNC SKIP
INR B
SKIP: DCR C
JNZ NEXT
INX H
DCR D
JNZ REPEAT
MOV A,B
MOV M,A
HLT
Solution:
Hint:
Algorithm:
1. Load the BCD number in the accumulator
2. Unpack the 2 digit BCD number into two separate digits. Let the left digit be BCD1and the right one BCD2
3. Multiply BCD1 by 10 and add BCD2 to it
If the 2 digit BCD number is 72, then its binary equivalent will be 7 x OAH + 2 = 46H + 2 = 48H
Input : 72H (0111 0010)2
Output : 48H (in hexadecimal) (0011 0000)2
((4x16)+(8x1))=72
Program:
LXI H,4350H
LXI D,4360H
MVI C,0AH
NEXTDATA:MOV A,M
ANI OFH
MOV B,A
PUSH B
MOV A,M
ANI F0H
JZ SKIPMULTIPLY
RLC
RLC
RLC
RLC
MVI C,0AH
MOV B,A
XRA A
AGAIN: ADD B
DCR C
JNZ AGAIN
SKIPMULTIPLY:POP B
ADD B
STAX D
INX H
INX D
DCR C
JNZ NEXTDATA
HLT
Solution:
LXI H,9205H
LXI D,A200H
NEXTDATA:MOV A,M
ADI 00H
JPO STORE
ANI DFH
ORI 08H
STORE: STAX D
MOV A,M
CPI 51H
JZ FINISH
INX H
INX D
JMP NEXTDATA
FINISH: HLT
Solution:
LXI H,9000H
LXI D,9020H
MVI C,0AH
NEXTDATA:MOV A,M
CPI 80H
JC SETBIT
ANI BFH
JMP STORE
SETBIT: ORI 20H
STORE:STAX D
INX H
INX D
DCR C
JNZ NEXTDATA
HLT
SOLUTION:
LXI H,A000H
LXI D,A030H
MVI C,0AH
NEXTDATA: MOV A,M
CPI 70H
JNC SKIP
CPI 25H
JC SKIP
JMP STORE
SKIP: MVI A,00H
STORE: STAX D
INX H
INX D
DCR C
JNZ NEXTDATA
HLT