8085 Assembly Language Programs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

http://www.scribd.

com/doc/26652705/8085-Assembly-Language-Programs-Explanations-1

8085 Assembly Language Programs & Explanations


1. Statement: Store the data byte 32H into memory location 4000H.
Program 1:
MVI A, 32H
: Store 32H in the accumulator
STA 4000H
: Copy accumulator contents at address 4000H
HLT
: Terminate program execution
Program 2:
L XI H
: Load HL with 4000H
MVI M
: Store 32H in memory location pointed by HL register pair
(4000H)
HLT
: Terminate program execution
2. Statement: Exchange the contents of memory locations 2000H and 4000H
Program 1:
LDA 2000H
: Get the contents of memory location 2000H into
accumulator
M OV B , A
: Save the contents into B register
LDA 4000H
: Get the contents of memory location 4000Hinto
accumulator
STA 2000H
: Store the contents of accumulator at address 2000H
MOV A, B
: Get the saved contents back into A register
STA 4000H
: Store the contents of accumulator at address 4000H
Program 2:
LXI H 2000H
: I nitialize HL register pair as a pointer to
memory location 2000H.
LXI D 4000H
: I nitialize DE register pair as a pointer to
memory location 4000H.
M OV B , M
: Get the contents of memory location 2000H into B
register.
L DAX 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.
HLT
: Terminate program execution.
3.Sample problem

( 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.

Program - 5.a: Add tw o 16-bit numbers - Source Program 1


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 I 6-bit number in HL
XCHG
: Save first I 6-bit number in DE
LHLD 4002H
: Get second I 6-bit number in HL
MOV A, E
: Get low er byte of the first number
ADD L
: Add low er byte of the second number
M OV 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 w ith CARRY
MOV H, A
: Store result in H register
SHLD 4004H
: Store I 6-bit result in memory locations 4004H and
4005H.
HLT
: Terminate program execution
6.Statement: Add the contents of memory locations 40001H and 4001H and place
the result in the memory locations 4002Hand 4003H.
Sample problem:
(4000H) = 7FH
(400lH) = 89H
Result = 7FH + 89H = lO8H
(4002H) = 08H
(4003H) = 0lH
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 the low er byte of result at 4002H
MVI A, 00
:I nitialize higher byte result with 00H
Source Program:
LXI H, 6000H
: I nitialize memory pointer
MVI C, 00H
: I nitialize number counter
MVI B, 00H
: I nitialize negative number counter
MVI E, 00H
: I nitialize zero number counter
BEGI N:MOV A, M
: Get the number
CPI 00H
: I f number = 0
JZ Z ER ONUM
: Goto zeronum
ANI
80H
: I f MSB of number = 1i.e. if
JNZ NEGNUM
number is negative goto NEGNUM
I NR D
: otherw ise increment positive number counter
JMP LAST
Z E R ON UM : I NR E
: I ncrement zero number counter
JMP LAST
NEGNUM:I NR B
: I ncrement negative number counter
LAST:I NX H
: I ncrement memory pointer
I NR C
: I ncrement number counter
MOV A, C
CPI 32H
: I f number counter = 5010 then
JNZ BEGI N
: Store
otherwise check next number
LXI H, 7000
: I nitialize 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
33.Statement:Write an 8085 assembly language program to insert a string of four
characters from the tenth location in the given array of 50 characters
S ol ut i o n:
Step 1: Move bytes from location 10 till the end of array by four bytes
dow nw ards.
Step 2: I nsert four bytes at locations 10, 11, 12 and 13.
Source Program:
LXI H, 2l31H
: I nitialize pointer at the last location of array.
LXI D, 2l35H
: I nitialize another pointer to point the last
location of array after insertion.
A GA I N : M OV A, M
: Get the character
STAX D
: Store at the new location
DCX D
: Decrement destination pointer
DCX H
: Decrement source pointer
MOV A, L
: [ check whether desired
CPI 05H
bytes are shifted or not]
JNZ AGAI N
: if not repeat the process
INX H
: adjust the memory pointer
LXI D, 2200H
: I nitialize the memory pointer to point the string to
be inserted
REPE: LDAX D
: Get the character
MOV M, A
: Store it in the array
INX D
: I ncrement source pointer
INX H
: I ncrement destination pointer
MOV A, E
: [ Check whether the 4 bytes
CPI 04
are inserted]
JNZ REPE
: if not repeat the process
HLT
: st op
34.Statement:Write an 8085 assembly language program to delete a string of 4
characters from the tenth location in the given array of 50 characters.
Solution: Shift bytes from location 14 till the end of array upw ards by 4
characters i.e. from location 10 onw ards.
Source Program:
LXI H, 2l0DH
:I nitialize source memory pointer at the 14thlocation
of the array.
LXI D, 2l09H
: I nitialize destn memory pointer at the 10th location
of the array.
MOV A, M
: Get the character
STAX D
: Store character at new location
INX D
: I ncrement destination pointer
INX H
: I ncrement source pointer
MOV A, L
: [ check whether desired
CPI 32H
bytes are shifted or not]
JNZ REPE
: if not repeat the process
HLT
: st op
35.Statement:Multiply the 8-bit unsigned number in memory location 2200H by
the 8-bit unsigned number in memory location 2201H. Store the 8 least significant
bits of the result in memory location 2300H and the 8 most significant bits in
memory location 2301H.

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

You might also like