8085 Assembly language programs.pdf

1,323 views 29 slides Nov 26, 2022
Slide 1
Slide 1 of 29
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29

About This Presentation

assembly programs of 8085 microprocessor, there are many programs related to the computer architecture that will helpful for the programming in the assembly language. like addition of two 8bit number , subtraction, multiplication, division and table for 8085, array,etc ....
Also written all the proc...


Slide Content

Assembly language programs
8085

8085 program to find maximum and
minimum of 10 numbers
In CMP instruction:
If Accumulator > Register then carry and zero
flags are reset
If Accumulator = Register then zero flag is set
If Accumulator < Register then carry flag is set
Assumption –List of numbers from 2050H to
2059H and output at 2060H and 2061H.
9/8/2022 7:34 AM 2

Algorithm
•MaximumnumberisstoredinBregisterandminimuminC
register
•LoadcounterinDregister
•LoadstartingelementinAccumulator,BandCregister
•CompareAccumulatorandBregister
•IfcarryflagisnotsetthentransfercontentsofAccumulator
toB.Else,compareAccumulatorwithCregister,ifcarry
flagissettransfercontentsofAccumulatortoC
•DecrementDregister
•IfD>0takenextelementinAccumulatorandgotopoint4
•IfD=0,storeBandCregisterinmemory
•Endofprogram
9/8/2022 7:34 AM 3

Program
2000H LXI H, 2050H
Load starting
address of list
2003H MOV B, M Store maximum
2004H MOV C, M Store minimum
2005H MVI D, 0AH
Counter for 10
elements
2007H LOOP MOV A, M
Retrieve list
element in
Accumulator
2008H CMP B
Compare element
with maximum
number
9/8/2022 7:34 AM 4

2009H JC MIN
Jump to MIN if not
maximum
200CH MOV B, A
Transfer contents
of A to B as A > B
200DH MIN CMP C
Compare element
with minimum
number
200EH JNC SKIP
Jump to SKIP if not
minimum
2011H MOV C, A
Transfer contents
of A to C if A <
minimum
2012H SKIP INX H Increment memory
9/8/2022 7:34 AM 5

2013H DCR D
Decrement
counter
2014H JNZ LOOP
Jump to LOOP if D
> 0
2017H LXI H, 2060H
Load address to
store maximum
201AH MOV M, B
Move maximum to
2060H
201BH INX H
Increment
memory
201CH MOV M, C
Move minimum to
2061H
201DH HLT Halt
9/8/2022 7:34 AM 6

Explanation
•OnebyoneallelementsarecomparedwithBand
Cregister.
•Elementiscomparedwithmaximum,ifitgreater
thanmaximumthenitisstoredinBregister.Else,
itiscomparedwithminimumandifitislessthan
minimumthenitstoredinCregiter.
•Loopexecutes10numberoftimes.
•Attheendof10iterations,maximumand
minimumarestoredat2060Hand2061H
respectively.
9/8/2022 7:34 AM 7

SMALLEST NUMBER IN A DATA ARRAY
Algorithm
1)LoadtheaddressofthefirstelementofthearrayinHLpair
2)MovethecounttoB–reg.
3)Incrementthepointer
4)GetthefirstdatainA–reg.
5)Decrementthecount.
6)Incrementthepointer
7)ComparethecontentofmemoryaddressedbyHLpairwiththatofA-reg.
8)Ifcarry=1,gotostep10orifCarry=0gotostep9
9)MovethecontentofmemoryaddressedbyHLtoA–reg.
10)Decrementthecount
11)CheckforZeroofthecount.IfZF=0,gotostep6,orifZF=1gotonextstep.
12)Storethesmallestdatainmemory.
13)Terminatetheprogram.
9/8/2022 7:34 AM 8

Program
LXI H,4200 Set pointer for array
MOV B,M Load the Count
INX H Set 1st element as largest data
MOV A,M
DCR B Decrementedthe count
LOOP: INX H
CMP M If A-reg< M go to AHEAD
JC AHEAD
MOV A,M Set the new value as smallest
AHEAD:DCR B
JNZ LOOP Repeat comparisons till count = 0
STA 4300 Store the largest value at 4300
HLT
9/8/2022 7:34 AM 9

Largest number in an array
9/8/2022 7:34 AM 10

9/8/2022 7:34 AM 11

9/8/2022 7:34 AM 12

Sort an array in ascending order
9/8/2022 7:34 AM 13

9/8/2022 7:34 AM 14

9/8/2022 7:34 AM 15

9/8/2022 7:34 AM 16

Sort an array in ascending order
Algorithm:
1. Initialize HL pair as memory pointer
2. Get the count at 4200 into C -register
3. Copy it in D -register (for bubble sort (N-1) times
required)
4. Get the first value in A -register
5. Compare it with the value at next location
6. If they are out of order, exchange the contents of A -register
and Memory
7. Decrement D -register content by 1
8. Repeat steps 5 and 7 till the value in D-register become
zero
9. Decrement C -register content by 1
10. Repeat steps 3 to 9 till the value in C -register becomes
zero
9/8/2022 7:34 AM 17

Program
LXIH,5000;Setpointerforarray
MOVC,M ;LoadtheCount
DCRC ;DecrementCount
REPEAT:MOVD,C
LXIH,5001
LOOP:MOVA,M ;copycontentofmemorylocationtoAccumulator
INXH
CMPM
JCSKIP;jumptoskipifcarrygenerated
MOVB,M ;copycontentofmemorylocationtoB-Register
MOVM,A ;copycontentofAccumulatortomemorylocation
DCXH ;DecrementcontentofHLpairofregisters
MOVM,B ;copycontentofB-Registertomemorylocation
INXH ;IncrementcontentofHLpairofregisters
SKIP:DCRD ;DecrementcontentofRegister-D
JNZLOOP ;jumptoloopifnotequaltozero
DCRC ;Decrementcount
JNZREPEAT;jumptorepeatifnotequaltozero
HLT ;TerminateProgram
9/8/2022 7:34 AM 18

Result
Input:
Data 0: 05H in memory location 5000 -->array size
Data 1: 05H in memory location 5001
Data 2: 04H in memory location 5002
Data 3: 03H in memory location 5003
Data 4: 02H in memory location 5004
Data 5: 01H in memory location 5005
Output:
Data 0: 05H in memory location 5000 --> array size
Data 1: 01H in memory location 5001
Data 2: 02H in memory location 5002
Data 3: 03H in memory location 5003
Data 4: 04H in memory location 5004
Data 5: 05H in memory location 5005
9/8/2022 7:34 AM 19

Sort an array in descending order
START:MVIB,00 ;Flag=0
LXIH,4150 ;Count=lengthofarray
MOVC,M
DCRC ;No.ofpair=count-1
INXH ;Pointtostartofarray
LOOP:MOVA,M ;Getkthelement
INXH
CMPM ;Compareto(K+1)thelement
JNCLOOP1 ;Nointerchangeifkth>=(k+1)th
MOVD,M ;Interchangeifoutoforder
MOVM,A ;
DCRH
MOVM,D
INXH
MVIB,01H ;Flag=1
LOOP1:DCRC ;countdown
JNZLOOP ;
DCRB ;isflag=1?
JZSTART ;doanothersort,ifyes
HLT ;Ifflag=0,stepexecution

9/8/2022 7:34 AM 20

To add numbers in an array
Problem–Writeanassemblylanguageprogram
toaddhexadecimalnumbersstoredin
continuousmemoryorinanarray.
Assumption–Supposethesizeofthearrayis
storedatmemorylocation2050andthebase
addressofthearrayis2051.Thesumwillbe
storedatmemorylocation3050andcarrywill
bestoredatlocation3051.
9/8/2022 7:34 AM 21

Algorithm
•LoadthebaseaddressofthearrayinHL
registerpair.
•Usethesizeofthearrayasacounter.
•Initialiseaccumulatorto00.
•Addcontentofaccumulatorwiththecontent
storedatmemorylocationgiveninHLpair.
•Decreasecounteroneachaddition.
9/8/2022 7:34 AM 22

Program
2000 LDA 2050 A <-[2050]
2003 MOV B, A B <-A
2004 LXI H, 2051H <-20 and L <-51
2007 MVI A, 00 A <-00
2009 MVI C, 00 C <-00
200B ADD M A <-A+M
200C INR M M <-M+1
200D JNC 2011
2010 INR C C <-C+1
2011 DCR B B <-B-1
2012 JNZ 200B
2015 STA 3050 3050 <-A
9/8/2022 7:34 AM 23

2018 MOV A, C A <-C
2019 STA 3051 3051 <-A
201C HLT
Terminates the program
9/8/2022 7:34 AM 24

Explanation –
LDA2050:loadaccumulatorwithcontentoflocation2050
MOVB,A:copycontentsofaccumulatortoregisterB
LXIH,2051:store20toHregisterand51toLregister
MVIA,00:store00toaccumulator
MVIC,00:store00toregisterC
ADDM:addaccumulatorwiththecontentsofmemorylocationgiveninHLregister
pair
INRM:increaseMby1
JNC2011:ifnotcarry,jumptolocation2011otherwisetothelocationgiveninPC
INRC:increasecontentofregisterCby1
DCRB:decreasecontentofregisterBby1
JNZ200B:ifnotzero,jumptolocation200BotherwisetothelocationgiveninPC
STA3050:storecontentsofaccumulatortomemorylocation3050
MOVA,C:copycontentsofregisterCtoaccumulator
STA3051:storecontentsofaccumulatortomemorylocation3051
HLT:terminatestheprogram
9/8/2022 7:34 AM 25

Square of a Number Using Look Up
Table
Algorithm
1.InitializeHLpairtopointLookuptable.
2.Getthedata.
3.Checkwhetherthegiveninputislessthan9.
4.Ifyesgotonextstepelsehalttheprogram.
5.Addthedesiredaddresswiththe
accumulatorcontent.
6.Storetheresult
9/8/2022 7:34 AM 26

Program and Result
LXIH,5000;InitialsieLookuptableaddress
LDA5050 ;Getthedata
CPI0A ;Checkinput>9
JCAFTER ;ifyeserror
VIA,FF ;ErrorIndication
STA5051
HLT
AFTER:MOVC,A ;AddthedesiredAddress
MVIB,00
DADB
MOVA,M
STA5051 ;Storetheresult
HLT ;Terminatetheprogram
9/8/2022 7:34 AM 27

LOOKUP TABLE
5000 01
5001 04
5002 09
5003 16
5004 25
5005 36
5006 49
5007 64
5008 81
9/8/2022 7:34 AM 28

Result
Input:
Data:05Hinmemorylocation5050
Output:
Data:25H(Squareof5)inmemorylocation5051
Input:
Data:11Hinmemorylocation5050
Output:
Data:FFH(ErrorIndication)inmemorylocation5051
9/8/2022 7:34 AM 29