8085 Program List With Explanation
8085 Program List With Explanation
1. Statement: Store the data byte 32H into memory location 4000H.
Program 1:
Program 2:
3. Statement: Subtract the contents of memory location 4001H from the memory
location 2000H and place the result in memory location 4002H.
Sample problem:
(4000H) = 51H
(4001H) = 19H
Result = 51H - 19H = 38H
Source program:
Sample problem:
(4000H) = 15H
(4001H) = 1CH
(4002H) = B7H
(4003H) = 5AH
Result = 1C15 + 5AB7H = 76CCH
(4004H) = CCH
(4005H) = 76H
Source Program 1:
LHLD 4000H : Get first I6-bit number in HL
XCHG : Save first I6-bit number in DE
LHLD 4002H : Get second I6-bit number in HL
MOV A, E : Get lower byte of the first number
ADD L : Add lower byte of the second number
MOV L, A : Store result in L register
MOV A, D : Get higher byte of the first number
ADC H : Add higher byte of the second number with CARRY
MOV H, A : Store result in H register
SHLD 4004H : Store I6-bit result in memory locations 4004H and
4005H.
HLT : Terminate program execution
5. Statement: Subtract the 16-bit number in memory locations 4002H and 4003H
from the 16-bit number in memory locations 4000H and 4001H. The most
significant eight bits of the two numbers are in memory locations 4001H and 4003H.
Store the result in memory locations 4004H and 4005H with the most significant
byte in memory location 4005H.
Sample problem
(4000H) = 19H
(400IH) = 6AH
(4004H) = I5H (4003H) = 5CH
Result = 6A19H - 5C15H = OE04H
(4004H) = 04H
(4005H) = OEH
Source program:
LHLD 4000H : Get first 16-bit number in HL
XCHG : Save first 16-bit number in DE
LHLD 4002H : Get second 16-bit number in HL
MOV A, E : Get lower byte of the first number
SUB L : Subtract lower byte of the second number
MOV L, A : Store the result in L register
MOV A, D : Get higher byte of the first number
SBB H : Subtract higher byte of second number with borrow
MOV H, A : Store l6-bit result in memory locations 4004H and
4005H.
SHLD 4004H : Store l6-bit result in memory locations 4004H and
4005H.
HLT : Terminate program execution
6. Statement: Find the l's complement of the number stored at memory location
4400H and store the complemented number at memory location 4300H.
Sample problem:
(4400H) = 55H
7. Statement: Find the 2's complement of the number stored at memory location
4200H and store the complemented number at memory location 4300H.
Sample problem:
(4200H) = 55H
Result = (4300H) = AAH + 1 = ABH
Source program:
8. Statement: Pack the two unpacked BCD numbers stored in memory locations
4200H and 4201H and store result in memory location 4300H. Assume the least
significant digit is stored at 4200H.
Sample problem:
(4200H) = 04
(4201H) = 09
Result = (4300H) = 94
Source program
Sample problem
(4200H) = 58
Result = (4300H) = 08 and
(4301H) = 05
Source program
10. Statement: Write a set of instructions to alter the contents of flag register in
8085.
11. Statement: Calculate the sum of series of numbers. The length of the series
is in memory location 4200H and the series begins from memory location
4201H.
a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory
location 4300H.
b. Consider the sum to be 16 bit number. Store the sum at memory locations 4300H
and 4301H
a. Sample problem
4200H = 04H
4201H = 01H
4202H = 02H
4203H = 03H
4204H = 04H
Source program:
LDA 4200H
MOV C, A : Initialize counter
SUB A : sum = 0
LXI H, 420lH : Initialize pointer
BACK: ADD M : SUM = SUM + data
INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 4300H : Store sum
HLT : Terminate program execution.
12.Write a program to count number of 1’s in given data (2000) and
store the result in memory location 3000H.
Sample problem:
(2200H) = 03H
(2201H) = B2H
Result = B2H + B2H + B2H = 216H
= 216H
(2300H) = 16H
(2301H) = 02H
Source program
LDA 2200H
MOV E, A
MVI D, 00 : Get the first number in DE register pair
LDA 2201H
MOV C, A : Initialize counter
LX I H, 0000 H : Result = 0
BACK: DAD D : Result = result + first number
DCR C : Decrement count
JNZ BACK : If count 0 repeat
SHLD 2300H : Store result
HLT : Terminate program execution
Next: INX H
DCR C
JNZ Loop
STA 9100H
HLT
Program –
MEMORY ADDRESS MNEMONICS COMMENT
2000 LDA 2050 A <- M[2050]
2003 ANI 01 A <- A (AND) 01
2005 JZ 200D Jump if ZF = 1
2008 MVI A 11 A <- 11
200A JMP 200F Jump to memory location
200D MVI A 22 A <- 22
200F STA 3050 M[3050] <- A
2012 HLT END
17. Calculate the sum of series of even numbers from the list of numbers. The
length of the list is in memory location 2200H and the series itself begins from
memory location 2201H. Assume the sum to be 8 bit number so you canignore
carries and store the sum at memory location 2Sample problem:
2200H= 4H
2201H= 20H
2202H= l5H
2203H= l3H
2204H= 22H
Result 22l0H= 20 + 22 = 42H
= 42H
Source program:
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 : Don't add if number is ODD
MOV A, B : Get the sum
ADD M : SUM = SUM + data
MOV B, A : Store result in B register
SKIP: INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 2210H : store sum
HLT : Terminate program execution