8085
8085
Program 1:
Program 2:
Program 2:
LXI H 2000H : Initialize HL register pair as a pointer to memory
location 2000H.
LXI D 4000H : Initialize DE register pair as a pointer to memory
location 4000H.
MOV B, M : Get the contents of memory location 2000H into B
register.
LDAX D : Get the contents of memory location 4000H into A
register.
MOV M, A : Store the contents of A register into memory location
2000H.
MOV A, B : Copy the contents of B register into accumulator.
STAX D : Store the contents of A register into memory location
4000H.
1
HLT : Terminate program execution.
2
Sample problem 1
4200H = 04H
4201H = 10H
4202H = 45H
4203H = 33H
4204H = 22H
Result = 10 +41 + 30 + 12 = H
4300H = H
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
b. Sample problem 2
4200H = 04H
420lH = 9AH
4202H = 52H
4203H = 89H
4204H = 3EH
Result = 9AH + 52H + 89H + 3EH = H
4300H = B3H Lower byte
4301H = 0lH Higher byte
Source program:
LDA 4200H
MOV C, A : Initialize counter
LXI H, 4201H : Initialize pointer
SUB A :Sum low = 0
MOV B, A : Sum high = 0
BACK: ADD M : Sum = sum + data
JNC SKIP
INR B : Add carry to MSB of SUM
3
SKIP: INX H : Increment pointer
DCR C : Decrement counter
JNZ BACK : Check if counter 0 repeat
STA 4300H : Store lower byte
MOV A, B
STA 4301H : Store higher byte
HLT :Terminate program execution
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
h. Divide 16 bit number stored in memory locations 2200H and 2201H
by the 8 bit number stored at memory location 2202H. Store the
quotient in memory locations 2300H and 2301H and remainder in
memory locations 2302H and 2303H.
Sample problem
(2200H) = 60H
(2201H) = A0H
(2202H) = l2H
4
Result = A060H/12H = 8E8H Quotient and 10H remainder
(2300H) = E8H
(2301H) = 08H
(2302H= 10H
(2303H) 00H
Source program
(2200H) = 04H
(2201H) = 56H
(2202H) = A9H
(2203H) = 73H
(2204H) = 82H
Source program
5
LDA 2200H
MOV C, A : Initialize count
MVI B, 00 : Negative number = 0
LXI H, 2201H : Initialize pointer
BACK: MOV A, M : Get the number
ANI 80H : Check for MSB
JZ SKIP : If MSB = 1
INR B : Increment negative number count
SKIP: INX H : Increment pointer
DCR C : Decrement count
JNZ BACK : If count 0 repeat
MOV A, B
STA 2300H : Store the result
HLT : Terminate program execution
j. Find the largest number in a block of data. The length of the block
is in memory location 2200H and the block itself starts from
memory location 2201H.
Store the maximum number in memory location 2300H. Assume that the
numbers in the block are all 8 bit unsigned binary numbers.
Sample problem
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
Source program
LDA 2200H
MOV C, A : Initialize counter
XRA A : Maximum = Minimum possible value = 0
LXI H, 2201H : Initialize pointer
BACK: CMP M : Is number> maximum
JNC SKIP : Yes, replace maximum
MOV A, M
SKIP: INX H
DCR C
JNZ BACK
STA 2300H : Store maximum number
6
HLT : Terminate program execution
MVI B, 00H
MVI C, 08H
MOV A, D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
HLT
l. 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 can ignore carries and store the sum
at memory location 2210H.
Sample 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
7
STA 2210H : store sum
HLT : Terminate program execution
m. Find the square of the given numbers from memory location 6100H
and store the result from memory location 7000H.
Source Program:
o. Add 2 arrays having ten 8-bit numbers each and generate a third
array of result. It is necessary to add the first element of array 1
with the first element of array-2 and so on. The starting addresses
8
of array l, array2 and array3 are 2200H, 2300H and 2400H,
respectively. Source Program:
Source Program:
LXI H, 2200H : Initialize memory pointer l
LXI D, 2300H : Initialize memory pointer2
MVI C, 32H : Initialize counter
BACK:MOV A, M : Get the number
ANI 0lH : Check for even number
JNZ SKIP : If ODD, don't store
MOV A, M : Get the number
STAX D : Store the number in result list
INX D : Increment pointer 2
SKIP: INX H : Increment pointer l
DCR C : Decrement counter
JNZ BACK : If not zero, repeat
HLT : Stop
Source Program:
9
MVI C, 00H : Initialize number counter
MVI B, 00H : Initialize negative number counter
MVI E, 00H : Initialize zero number counter
BEGIN:MOV A, M : Get the number
CPI 00H : If number = 0
JZ ZERONUM : Goto zeronum
ANI 80H : If MSB of number = 1i.e. if
JNZ NEGNUM number is negative goto NEGNUM
INR D : otherwise increment positive number counter
JMP LAST
ZERONUM:INR E : Increment zero number counter
JMP LAST
NEGNUM:INR B : Increment negative number counter
LAST:INX H : Increment memory pointer
INR C : Increment number counter
MOV A, C
CPI 32H : If number counter = 5010 then
JNZ BEGIN : Store otherwise check next number
LXI H, 7000 : Initialize memory pointer.
MOV M, B : Store negative number.
INX H
MOV M, E : Store zero number.
INX H
MOV M, D : Store positive number.
HLT : Terminate execution
r. Program to calculate the factorial of a number between 0 to 8
Source program
10
Subroutine Program:
FACTO:LXI H, 0000H
MOV B, C ; Load counter
BACK: DAD D
DCR B
JNZ BACK ; Multiply by successive addition
XCHG ; Store result in DE
DCR C ; Decrement counter
CNZ FACTO ; Call subroutine FACTO
RET ; Return to main program
Source Program:
Subroutine:
11
INR D : Increment the quotient
CMP C : Repeat subtraction until the
JNC NEXT : divisor is less than dividend
RET : Return to main program
12