8085 Assembly Language Programs
8085 Assembly Language Programs
8085 Assembly Language Programs
com/doc/26652705/8085-Assembly-Language-Programs-Explanations-1
( 40 00 H) = 1 4H (4 00 1H ) = 89 H R e s ul t
= 14H + 89H = 9DH
Source program
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 result at 4002H
HLT
: Terminate program execution
4.Statement: Subtract the contents of memory location 4001H from the memory
location 2000H and place the result in memory location 4002H.
Program - 4: Subtract tw o 8-bit numbers
Sample problem:
(4000H)
= 51H
(4001H)
= 19H
R e s ul t
= 51H - 19H = 38H
Source program:
LXI H, 4000H
: HL points 4000H
MOV A, M
: Get first operand
INX H
: HL points 4001H
SUB
M
: Subtract second operand
INX H
: HL points 4002H
MOV M, A
: Store result at 4002H.
HLT
: Terminate program execution
5.Statement: Add the 16-bit number in memory locations 4000H and 4001H to
the 16-bit number in memory locations 4002H and 4003H. The most significant eight bits of the two numbers to
be added 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:
(2200)
= 1100 (0CH)
(2201)
= 0101 (05H)
Multiplicand
= 1100 (1210)
Multiplier
= 0101 (510)
R e s ul t
= 12 x 5 = (6010)
Source program
LXI H, 2200
: I nitialize the memory pointer
M OV E , M
: Ge t m ul t i pl i c a n d
MVI D, 00H
: Extend to 16-bits
INX H
: I ncrement memory pointer
MOV A, M
: Get multiplier
LXI H,0 0 0 0
: Product = 0
MVI B, 08H
: I nitialize counter w ith count 8
M UL T : DA D H
: Product = product x 2
R AL
JN C SKI P
: I s carry from multiplier 1 ?
DAD D
: Ye s, P ro du c t = Pr od uc t + Mu l t i p l i c a nd
SKIP: DCR B
: I s counter = zero
JNZ MULT
: no, repeat
SHLD 2300H
: Store the result
HLT
: End of program
36.Statement:Divide the 16-bit unsigned number in memory locations 2200H and
2201H (most significant bits in 2201H) by the B-bit unsigned number in memory
location 2300H store the quotient in memory location 2400H and remainder in
2401H
A ss um pt i o n: T h e m os t s i g ni fi c a nt bi t s of bo th the di vi so r a nd di vi de nd ar e
zero.
Source program
MVI E, 00
: Quotient = 0
LHLD
2200H
: Get dividend
LDA 2300
: Ge t divisor
M OV B , A
: Store
divisor
MVI C, 08
: Count = 8
NEXT: DAD H
: Dividend = Dividend x 2
MOV A, E
RLC
M OV E , A
: Quotient = Quotient x 2
MOV A, H
SUB B
: I s m o st si gn i f i c a n t b yt e o f D i v i de nd > d iv is or
JC SKI P
: No, go to Next step
MOV H, A
: Ye s, s ub t r a c t d i v i s or
I NR E
: and Quotient = Quotient + 1
SKI P:DCR C
: Count = Count - 1
JNZ NEXT
: I s count = 0 repeat
MOV A, E
STA 2401H
: Store Quotient
Mov A, H
STA 2410H
: Store remainder
HLT
: End of program
37.DAA instruction is not present. Write a sub routine which will perform the same
task as DAA.
Sample Problem:
E xe c u t i on of DA A i ns t r uc t i on :
1. I f the value of the low order four bits ( 03-00) in the accumulator is
greater than 9 or if auxiliary carry flag is set, the instruction adds 6 '( 06) to
the low -order four bits.
2. I f the value of the high-order four bits (07-04) in the accumulator is
greater than 9 or if carry flag is set, the instruction adds 6( 06) to the high-
order four bits.
Source Program:
LXI SP, 27FFH
: I nitialize stack pointer
M OV E , A
: Store the contents of accumulator
ANI 0FH
: Mask upper nibble
CPI 0A H
: Check if number is greater than 9
JC SKI P
: i f no go t o sk i p
MOV A, E
: Get the number
ADI 06H
: Add 6 in the number
JMP SECOND
: Go for sec ond c hec k
SKI P: PUSH PSW
: Store accumulator and flag contents in stack
P OP B
: Get the contents of accumulator in B register and
flag register contents in
C register
MOV A, C
: Get flag register contents in accumulator
ANI 10H
: C h e c k f or bi t 4
JZ SECOND
: i f z e ro, go fo r s e c o nd c h e c k
MOV A, E
: Get the number
ADI 06
: Add 6 in the number
SEC OND: MOV E, A
: Store the contents of accumulator
A NI FO H
: Mask low er nibble
R RC
R RC
R RC
R RC
: Rotate number 4 bit right
C PI 0AH
: Check if number is greater than 9
JC SKI Pl
: i f no go t o sk i p 1
MOV A, E
: Get the number
ADI 60 H
: Add 60 H in the number
JMP LAST
: Go to la st
SKI P1: JNC LAST
: if carry flag = 0 go to last
MOV A, E
: Get the number
ADI 60 H
: Add 60 H in the number
LAST: HLT
38.tement:To test RAM by writing '1' and reading it back and later writing '0'
(zero) and reading it back. RAM addresses to be checked are 40FFH to 40FFH. In
case of any error, it is indicated by writing 01H at port 10H
Source Program:
LXI H, 4000H
: I nitialize memory pointer
BACK: MVI M, FFH
: Writing '1' into RAM
MOV A, M
: Reading data
f ro m R AM
CPI FFH
: Chec k for ER ROR
JNZ ERROR
: I f ye s g o t o E R R OR
INX H
: I ncrement memory pointer
MOV A, H
CPI SOH
: Chec k for la st che ck
JNZ BACK
: I f not last, repeat
LXI H, 4000H
: I nitialize memory pointer
B AC Kl : MVI M, OOH
: Writing '0' into RAM
MOV A, M
: Reading data from RAM
C PI OOH
: Check for
ERROR
INX H
: I ncrement memory pointer
MOV A, H
CPI SOH
: Chec k for la st che ck
JNZ BACKl
: I f not last, repeat
HLT
: St op E x e c ut i o n
39.tement:Write an assembly language program to generate fibonacci number
Source Program:
MVI D, COUNT
: I nitialize counter
MVI B, 00
: I nitialize variable to store previous number
MVI C, 01
: I nitialize variable to store current number