mp and mc 2015
TRANSCRIPT
-
8/10/2019 mp and mc 2015
1/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 1
PSN COLLEGE OF ENGINEERING AND TECHNOLOGY
Melathediyoor, Tirunelveli(Approved by AICTE and Recognized by UGC Section 2 (f)
An ISO 9001:2008 Certified Institution(Accredited by NBA and NAAC, Affiliated to Anna University of Technology,
Tirunelveli)
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
MICROPROCESSOR
AND
MICROCONTROLLER
Prepared by
T.Rajesh M .E.,(Ph.D) AP/ECE
K.Manikandan M .E., AP/ECE
LABORATORY
MANUAL
-
8/10/2019 mp and mc 2015
2/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 2
SYLLABUS
MICROPROCESSOR AND MICROCONTROLLER LABORATORY
LIST OF EXPERIMENTS
Microprocessor (8085/8086):
1. Program for 8 bit Arithmetic operation using 8085/86
2. Program for 16 bit Arithmetic operation using 8085/86
3. Program for sorting and searching using 8085/86
4. Program for String manipulation operation using 8085/86
Microcontroller:
1. Programming using Arithmetic, Logical and bit manipulation instructions of 8051
2. Program for sorting and searching using 8051
3. Code conversion using 8051.
Interfacing:
1. Analog to Digital/ Digital to Analog
2. Interfacing and programming of stepper motor control
3. Communication between 8051 Microcontroller and PC
4. Interfacing and programming 8279, 8259, 8255 and 8253.
5. Traffic Light Controller.
TOTAL : 45 PERIODS
L T P C
0 0 3 2
-
8/10/2019 mp and mc 2015
3/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 3
MICROPROCESSOR AND MICROCONTROLLER LABORATORY
Sl.No Cycle I Page No
1. Program for 8 bit Arithmetic operation using 8085
2. (a) Program for 16 bit Arithmetic operation using 8085
2. (b) Program for 16 bit Arithmetic operation using 8086
3. (a) Program for sorting and searching using 8085
3. (b) Program for sorting and searching using 8086
4. Program for String manipulation operation using 8086
5. Programming using Arithmetic, Logical and bit manipulation instructions of
8051
Cycle II
6. Program for sorting and searching using 8051
7. Code conversion using 8051.
8. Analog to Digital/ Digital to Analog
9. Interfacing and programming of stepper motor control
10. Communication between 8051 Microcontroller and PC
11. Interfacing and programming 8279, 8259, 8255 and 8253.
12. Traffic Light Controller.
-
8/10/2019 mp and mc 2015
4/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 4
EXP.NO.
TITLE:
Date:_________STUDYOFINTEL8085MICROPROCESSORKIT
Aim: TostudytheworkingofIntel8085Microprocessortrainerkit.
Figure1.1 VimicrosMicro-85Microprocessorkit
1.1INTRODUCTION
This section briefs the hardware and software facilities available in both the trainers
Micro-85 EBl and Micro-85 EB2. Micro-85 EBl is a powerful Microprocessor Trainer
with basic features such as 24 TTL lines using 8255, Hardware Single Stepping and
SoftwareSingleSteppingofuserprograms.
In addition to the above features, Micro-85 EB2 has RS232C compatible serial port,
Bus Expansion for interfacing VBMB series of add-on cards and 24 TTL I/O lines.A
separate switch is provided for learning more about hardware. interrupts. There is
also provision to add multi output power supply for interfacing experiment boards.
Most of the control signals are terminated .at test points for easy analysis on CRO or
logicprobe.
-
8/10/2019 mp and mc 2015
5/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 5
The differences in the specification of Micro-85 EBl and Micro-85EB2 are highlighted
in this manual. The users are therefore requested to go through the Hardware
specificationcarefully.
1.2 SPECIFICATIONS
1.2.1HARDWARESPECIFICATIONS
1)PROCESSOR,CLOCKFREQUENCY:Intel8085Aat6.144MHzclock..
2)MEMORY:
MonitorEPROM
EPROM-Expansion
SystemRAM
MonitorDataArea
UserRAMArea
RAM-Expansion
:0000-1FFF
:2000-3FFF&COOO-FFFF
:4000-5FFF
:4000-40FF(Reserved)
:4100-5FFF
:6000-BFFF
Note:TheRAMareafrom4000-40FFshouldnotbeaccessedbythe
usersinceit isusedasscratchpadbytheMonitorprogram.
3)INPUT/OUTPUT:
Parallel:48TTL:I/O linesusingtwonumberof8255
(only24:I/Oline.availableinmicro-85EB1).
Serial :OnenumberofRS232C compatibleSerial interface
using8251A-USART.
Timer :Threechannel16-bitProgrammableTimerusing8253.-Channel0 isusedasbaudrateclockgenerator for8251AUSART.
-Channel1 isusedfor insinglesteppinguserprograms.-Channel2 isusedforHardwareSingleSteppinguserprograms.
4)DISPLAY:- 6digit,0.3",7SegmentRedLEDDisplaywithfilter.- 4digits foraddressdisplayand2digitsfordatadisplay.
5)KEYBOARD:- 21Keyssoftkeyboard includingcommandkeysandhexa-decimalkeys.
6)AUDIOCASSETTEINTERFACEwithfilemanagement.
7)BATTERYBACKUP:-OnboardBatterybackupfacility isprovided fortheavailableRAM.
-
8/10/2019 mp and mc 2015
6/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 6
8) HARDWARESINGLESTEP:Thisfacilityallowstheusertoexecuteprogramsatmachinecycle level
usingaseparateswitch.
9) SYSTEMPOWER CONSUMPTION:
Micro-85EB2
+5V@ 1Amp
+12V@ 200mA-12V@ l00mA
Micro-85EBl
+5V@ 500mA
10) POWER SUPPLYSPECIFICATIONS:[External]
Micro-85EB2
Input: 230VAC @ 50,Hz
Micro-85EB1
230VAC @ 50Hz
Output:+5V @ 1.5A +5V@ 600mA
+12V@ 150mA
-12V@ 150mA+30V@ 250mA(Unregulated)
11) PHYSICALCHARACTERISTICS:
Micro-85EB PCB :230mmx170mm[LxB] Weight :1Kg.
12) TESTPOINTS: TestpointsprovidedforMR*,MW*,INTA*,IO/M*,IOR*,IOW*,S0,S1,INTA.
Thisenablestheusertostudythehardwaretimingeasily.
-
8/10/2019 mp and mc 2015
7/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 7
1.2.2 SOFTWARESPECIFICATIONS
Micro-S5 EB contains a high performance 8K bytes monitor program. It is designed
to respond to user input, RS232C serial communications, tape interface etc. The
following is a simple description of the key functions. Out of the 21 keys in the
keyboard 16 are hexadecimal, command and register keys and the remaining arestand-alonekeys.
KEY FUNCTIONSUMMARY
ThisRESkeyallowsyou toterminateanypresentactivityandtoreturnyourMicro-85EB to an initialized state.When pressed, the ..85 sign-
RES on message appears in the display for a few seconds and the monitorwilldisplaycommandprompt- inthe leftmostdigit.
Maskable interruptconnectedtoCPU'sRST7.5 interrupt.
INT
Decrementtheaddressbyoneanddisplay itcontents
(or)
DEC Displaythepreviousregistercontents.
Executeaparticularprogramafterselectingtheaddress
EXECthroughGOcommand.
Incrementaddressbyoneanddisplay itscontents
(or)
DEC Displaythenextregistercontent.
The16Hexadecimalkeyshaveeitheradualoratripleroletoplay.
i)ItfunctionsasaHexkeyentrywhenaaddressordataentry isrequired.
ii)ItfunctionsastheRegisterkeyentryduringRegistercommand.
iii)It functionsascommandkeywhenpresseddirectlyaftercommandprompt.
NOTE: TheHex-keyfunctionsummarybelow is intheorder:
i) Hexkey.ii) Commandkey
iii) Registerkey.
-
8/10/2019 mp and mc 2015
8/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 8
KEY FUNCTIONSUMMARY
i. Hexkeyentry"0"
0E
SUB
DREG
2C
TW
ii.Thiskey isforsubstitutingmemorycontentsWhenNEXTkey is
pressed immediate1yafterthis ittakestheusertothestart
addressforenteringuserprograms,4100Hex(UserRAM).iii.Registerkey"E"
i. Hexkeyentry"1"
ii.Examinethe8085Aregistersandmodifythesame.
iii.Registerkey"D"
i. Hexkeyentry"2"
ii.Writesdatafrommemoryontoaudiotape.
iii.Registerkey"C"
3 i. Hexkeyentry3B
TRii. Retrievedata fromanaudiotapetomemory.
iii.RegisterkeyB
4i. Hexkeyentry4.
F ii. Blocksearch forabyte.BLOC
iii.RegisterkeyF.
5i. Hexkeyentry5.
A ii. FillablockofRAMmemorywithdesireddata.
FILLiii.RegisterkeyA.
6i. Hexkeyentry"6"
L ii. Transmit/Receivedatato/fromtheserialport.SER
TheTW/TR keysareusedforsending/receivingrespectively.
iii.RegisterkeyL.
7 i. Hexkeyentry"7"H
F2 ii. Registerkey"H"
-
8/10/2019 mp and mc 2015
9/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 9
8I
GO
i. Hexkeyentry"8"
ii. Startrunningaparticularprogram
iii.Registerkey"I"
9i. Hexkeyentry"9"
PL
SNG
APH
F3
ii. Singlestepaprogram instructionbyinstruction.
iii.RegisterkeyPCL.
i Hexkeyentry"A"
ii. FunctionkeyF3F3[0]=Inputabytefromaport
P3[1]=Outputabytetoaport
iii.RegisterkeyPCH"
iv.UsedwithSNG keyforhardwaresinglestepping.
B i Hexkeyentry"B"
SLBC
ii. Checkaparticularblockforblank.
iii.Registerkey"SPL"
C i. Hexkeyentry"C"SH
MOVii. Moveblockofmemorytoanotherblock
iii. RegisterkeySPH
D i. Hexkeyentry"D"
CMPii. Comparetwomemoryblocks.
E i. Hexkeyentry"E"
INSii. Insertbytes intomemory(RAM).
Fi.Hexkeyentry"F"
DEL ii.Deletebytesfrommemory(RAM).
-
8/10/2019 mp and mc 2015
10/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 10
EXP.NO.
TITLE:
Date:_________
STUDYOFINTEL8086MICROPROCESSOR
FEATURES:
1. 16-bitDatabus2. Computes16bit/32bitdata.3. 20-bitaddressbus.4. Morememoryaddressingcapability(2
20=1MB)
5. 16bitFlagregisterwith9Flags6. Canbeoperated inMinimummodeandMaximummode
7. Hastwostagepipelinedarchitecture8. No internalclockgeneration9. 40pinDIPIC -HMOStechnology10.Operateson+5Vsupplyvoltage11.Hasmorepowerful instructionset
Memory:
Program, data and stack memories occupy the same memory space. The total
addressable memory size is 1MB KB.As the most of the processor instructions use
16-bit pointers the processor can effectively address only 64 KB of memory. To
access memory outside of 64 KB the CPU uses special segment registers to specify
where the code, stack and data 64 KB segments are positioned within 1 MB of
memory(seethe"Registers"sectionbelow).
-
8/10/2019 mp and mc 2015
11/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 11
16-bitpointersanddataarestoredas:
address
address+1
: low-orderbyte
:high-orderbyte
32-bitaddressesarestoredin"segment:offset"formatas:
address
address+1
address+2
address+3
: low-orderbyteofsegment
:high-orderbyteofsegment
: low-orderbyteofoffset
:high-orderbyteofoffset
PhysicalmemoryaddresspointedbySEGMENT:OFFSETpair iscalculatedas:
Physicaladdress=(*16)+
Programmemory - program can be located anywhere in memory. Jump and
call instructions can be used for shortjumps within currently selected 64 KB
code segment, as well as for farjumps anywhere within 1 MB of memory. All
conditionaljump instructions can be used tojump within approximately +127 -
-127 bytesfromcurrent instruction.
Data memory - the processor can access data in any one out of 4
availablesegments, which limits the size of accessible memory to 256 KB (if
all four segments point to different 64 KB blocks). Accessing data from the
Data, Code,Stack or Extra segments can be usually done by prefixing instructionswith the DS:,CS:, SS: or ES: (some registers and instructions by default may use
the ES or SSsegments insteadofDSsegment).
Word data can be located at odd or even byte boundaries. The processor uses two
memory accesses to read 16-bit word located at odd byte boundaries. Reading
worddatafromevenbyteboundariesrequiresonlyonememoryaccess.
Stackmemory can be placed anywhere in memory. The stack can be located at
odd memory addresses, but it is not recommended for performance reasons (see
"DataMemory"above).
Reservedlocations:
0000h - 03FFh are reserved for interrupt vectors. Each interrupt vector is a
32-bitpointer informatSEGMENT:OFFSET.
FFFF0h -FFFFFh-afterRESET theprocessoralwaysstartsprogram execution
attheFFFF0haddress.
-
8/10/2019 mp and mc 2015
12/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 12
Interrupts:
Theprocessorhasthefollowing interrupts:
INTR is a maskable hardware interrupt. The interrupt can be enabled/disabled
using STI/CLI instructions or using more complicated method of updating the
FLAGS register with the help of thePOPF instruction. When an interrupt occurs, the
processor storesFLAGS register into stack, disables further interrupts, fetches from
the bus one byte representing interrupt type, andjumps to interrupt processing
routine address of which is stored in location 4 * . Interrupt
processingroutineshouldreturnwiththeIRET instruction.
NMI is a non-maskable interrupt. Interrupt is processed in the same way as the
INTR interrupt. Interrupt type of the NMI is 2, i.e. the address of the NMI
processing routine is stored in location 0008h. This interrupt has higher priority
thenthemaskable interrupt.
Softwareinterruptscanbecausedby:
INT instruction-breakpoint interrupt.This isatype3 interrupt.
INT instruction - any one interrupt from available 256
interrupts.
INTO instruction- interruptonoverflow
Single-step interrupt - generated if the TF flag is set. This is a type 1
interrupt.When the CPUprocesses this interrupt itclearsTF flagbeforecalling
the interruptprocessingroutine.
Processor exceptions: divide error (type 0), unused opcode (type 6) and
escapeopcode(type7).
Softwareinterruptprocessing isthesameasforthehardware interrupts.
I/Oports:
8086 can interface maximum of 65536 nos of 8-bit I/O ports. These ports can be
alsoaddressedas3276816-bitI/Oports.
-
8/10/2019 mp and mc 2015
13/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 13
Registers:
Most of the registers contain data/instruction offsets within 64 KB memory
segment. There are four different 64 KB segments for instructions, stack, data and
extra data. To specify where in 1 MB of processor memory these 4 segments are
locatedtheprocessorusesfoursegmentregisters:
Code segment (CS) is a 16-bit register containing address of 64 KB segment with
processor instructions. The processor uses CS segment for all accesses to
instructions referenced by instruction pointer (IP) register. CS register cannot be
changed directly. The CS register is automatically updated during farjump, far call
andfarreturn instructions.
Stack segment (SS) is a 16-bit register containing address of 64KB segment with
program stack. By default, the processor assumes that all data referenced by the
stack pointer (SP) and base pointer (BP) registers is located in the stack segment.
SSregistercanbechangeddirectlyusingPOP instruction.
Data segment (DS) is a 16-bit register containing address of 64KB segment with
program data. By default, the processor assumes that all data referenced by
general registers (AX, BX, CX,DX)and index register (SI,DI) is located in thedata
segment.DSregistercanbechangeddirectlyusingPOPandLDS instructions.
Extra segment (ES) is a 16-bit register containing address of 64KB segment,
usually with program data. By default, the processor assumes that the DI register
references the ES segment in string manipulation instructions. ES register can be
changeddirectlyusingPOPandLESinstructions.
It is possible to change default segments used by general and index registers by
prefixing instructionswithaCS,SS,DSorESprefix.
All general registers of the 8086 microprocessor can be used for arithmetic and
logicoperations.Thegeneralregistersare:
Accumulator (AX) register consists of 2 8-bit registersAL andAH, which can be
combined together and used as a 16-bit registerAX.AL in this case contains the
low-order byte of the word, andAH contains the high-order byte.Accumulator can
beused forI/Ooperationsandstringmanipulation.
Base(BX) register consists of 2 8-bit registers BL and BH,which can becombined
together and used as a 16-bit register BX. BL in this case contains the low-order
byteof the word, and BH contains the high-order byte. BX register usually contains
adatapointerusedforbased,based indexedorregister indirectaddressing.
-
8/10/2019 mp and mc 2015
14/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 14
Count (CX) register consists of 2 8-bit registers CL and CH, which can be
combined together and used as a 16-bit register CX. When combined, CL register
contains the low-order byte of the word, and CH contains the high-order byte.
Count register can be used as a counter in string manipulation and shift/rotate
instructions.
Data(DX) registerconsistsof2 8-bit registers DL and DH,whichcanbecombinedtogetherand usedasa16-bit registerDX.Whencombined,DL registercontainsthe
low-order byte of the word, and DH contains the high-order byte. Data register can
be used as a port number in I/O operations. In integer 32-bit multiply and divide
instruction the DX register contains high-order word of the initial or resulting
number.
Thefollowingregistersarebothgeneraland indexregisters:
StackPointer(SP) isa16-bitregisterpointingtoprogramstack.
Base Pointer (BP) is a 16-bit register pointing to data in stack segment.
BPregister isusuallyused forbased,based indexedorregister indirectaddressing.
Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed
and register indirect addressing, as well as a source data address in string
manipulationinstructions.
Destination Index (DI) is a 16-bit register. DI is used for indexed, based
indexedand register indirect addressing, as well as a destination data address
in stringmanipulation instructions.
Otherregisters:
InstructionPointer(IP) isa16-bitregister.
FlagRegisterisa16-bitregistercontaining9nosofonebitflags:
Overflow Flag (OF) - set if the result is too large positive number, or is too
smallnegativenumbertofit intodestinationoperand.
Direction Flag (DF) - if set then string manipulation instructions will auto-
decrement index registers. If cleared then the index registers will be auto-
incremented.
Interrupt-enableFlag(IF)-settingthisbitenablesmaskable interrupts.
Single-stepFlag(TF)- ifsetthensingle-step interruptwilloccurafterthenext
instruction.
SignFlag(SF)-set ifthemostsignificantbitoftheresult isset.
ZeroFlag(ZF)-set iftheresult iszero.
-
8/10/2019 mp and mc 2015
15/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 15
Auxiliary carryFlag (AF) - set if there was a carry from or borrow to bits 0-3
intheALregister.
ParityFlag(PF)-set ifparity(thenumberof"1"bits) inthe low-orderbyteof
theresult iseven.
Carry Flag (CF) - set if there was a carry from or borrow to the most
significantbitduringlastresultcalculation.
InstructionSet:
8086instructionsetconsistsofthe following instructions:
Datamoving instructions.
Arithmetic - add, subtract, increment, decrement, convert byte/word and
compare.
Logic-AND,OR,exclusiveOR,shift/rotateandtest.
Stringmanipulation- load,store,move,compareandscanforbyte/word.
Control transfer - conditional, unconditional, call subroutine and return from
subroutine.
Input/Output instructions.
Other-setting/clearing flagbits,stackoperations,software interrupts,etc.
Addressingmodes:
Implied-thedatavalue/dataaddress is implicitlyassociatedwiththe instruction.
Register-referencesthedata inaregisteror inaregisterpair.
Immediate-thedata isprovided inthe instruction.
Direct - the instruction operand specifies the memory address where data is
located.
Register indirect - instruction specifies a register containing an address, where
datais located.ThisaddressingmodeworkswithSI,DI,BXandBPregisters.
Based - 8-bit or 16-bit instruction operand is added to the contents of a baseregister(BXorBP),theresultingvalueisapointerto locationwheredataresides.
Indexed - 8-bit or 16-bit instruction operand is added to the contents of an index
register(SIorDI),theresultingvalue isapointerto locationwheredataresides.
-
8/10/2019 mp and mc 2015
16/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 16
Based Indexed - the contents of a base register (BX or BP) is added to the
contents of an index register (SI or DI), the resulting value is a pointer to location
wheredataresides.
Based Indexedwith displacement - 8-bit or 16-bit instruction operand is added
to the contents of a base register (BX or BP) and index register (SI or DI), the
resultingvalue isapointerto locationwheredataresides.
Result:
ThefeaturesoftheIntel8085&8086microprocessorswerestudiedandoperations
ofthecorrespondingkitswereunderstood.
-
8/10/2019 mp and mc 2015
17/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 17
Fig.Flowchartfor8-bitAdditionwithcarry
-
8/10/2019 mp and mc 2015
18/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 18
EXP.NO. Date:_________
TITLE: 8-BITARITHMETICOPERATIONS (8-BITADDITION)
AIM: Towriteanassembly languageprogram fortheadditionoftwo8-bitnumbers.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
The two operands (i.e., 8-bit numbers) are loaded into two registersA & B, using
immediate addressing mode instructions and then added usingADD instruction. The
result is stored in the desired memory location. The overflow in addition is checked
byverifying thestatusofCarry(Cy)flagandaccordinglyeither00or01 isstored
inthe locationnexttotheresult.
ALGORITHM:
1.Starttheprogram
2.InitializetheC registeras00H.
3.Movethedata1anddata2toAccumulatorandBregisterrespectively.
4.AddBregistertothecontentofaccumulator
5.Ifthere isnocarry,gotostep6,else incrementC register.
6.Storethecontentofaccumulator tothememorylocation4500H.
7.MovethecontentofC registertoaccumulator.
8.Storethecontentofaccumulator tothememorylocation4501H.
9.Stoptheprogram.
-
8/10/2019 mp and mc 2015
19/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 19
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4100 0E,00 MVIC,00 Clearcregister
4102 3E,Data1 MVIA,Data1Movedata1toaccumulator
4104 06,Data2 MVIB,Data2 Movedata2toBRegister
4106 80 ADDB AddBRegtoaccumulator
4107 D2,0B,41 JNC GOJumponNocarrytolocationGO
410A 0C INR C IncrementC Register
410B 32,00,45 GO: STA4500 Storetheresult
410E 79 MOVA,C MovecarrytoAcc
410F 32,01,45 STA4501 Storethecarry
4112 76 HLT Stoptheprogram
MANUALCALCULATION:
-
8/10/2019 mp and mc 2015
20/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 20
SAMPLEDATA:
Resultof8-bitadditionwithoutcarry:
INPUT OUTPUT
Address Data Address Data
4103 05H4500
(Result) 0BH
4105 06H4501
(Carry) 00H
Resultof8-bitadditionwithcarry:
INPUT OUTPUT
Address Data Address Data
4103 51H
4500
(Result) 3CH
4105 EBH4501
(Carry) 01H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
41034500
(Result)
41054501
(Carry)
RESULT:
Thustheassembly languageprogram for8-bitaddition isexecutedandtheresults
areverified.
-
8/10/2019 mp and mc 2015
21/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 21
Fig.Flowchartfor8-bitsubtraction
-
8/10/2019 mp and mc 2015
22/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 22
EXP.NO. Date:_________
TITLE: 8-BITARITHMETICOPERATION(8-BITSUBTRACTION)
AIM:Towriteanassembly languageprogramforthesubtractionoftwo8-bit
numbers,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
Out of the twooperands forsubtraction, the firstoperand is loaded intoAccumulator
and the second operand is subtracted directly from memory, using register indirect
addressing mode instructions. The result is stored in desired memory location and
the borrow in subtraction is checked by verifying the status of Carry (Cy) flag and
accordinglyeither00or01 isstored inthelocationnexttoresult.
ALGORITHM:
1.Starttheprogram.
2.LoadtheHLpairwith16-bitaddressofdata location.
3.MovethecontentofmemoryaddressinHLtoaccumulator.
4.Incrementtheaddress inHLpair.
5.Subtractthecontentofmemory fromaccumulator.
6.JumponNo-carrytostep8.
7.IncrementtheC-register.
8.StorethecontentofaccumulatorandC-register.
9.Stoptheprogram.
-
8/10/2019 mp and mc 2015
23/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 23
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4100 21,50,41 LXIH,4150 LoaddatatoHLRegister
4103 7E MOVA,M MoveData1toAcc
4104 0E,00 MVIC,00 ClearC-register.
4106 23 INXH Incrementaddress.
4107 96 SUBM SubtractData2 fromAcc
4108 D2,0C,41 JNC NEXTJumponNo-carrytothe locationNEXT.
410B 0C INR C IncrementC register
410C 32,52,41 NEXT: STA4152 Storetheresult
410F 79 MOVA,C Movecarrytoacc
4110 32,53,41 STA4153 Storethecarry4113 76 HLT Stoptheprogram
MANUALCALCULATION:
-
8/10/2019 mp and mc 2015
24/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 24
SAMPLEDATA:
Resultof8bitsubtractionwithoutcarry:
INPUT OUTPUT
Address Data Address Data
4150 68H4152
(Result) 14H
4151 54H4153
(Borrow) 00H
Resultof8bitsubtraction withcarry:
INPUT OUTPUT
Address Data Address Data
4150 57H
4152
(Result) F1H
4151 66H4153
(Borrow) 01H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
41504152
(Result)
41514153
(Borrow)
RESULT:
Thustheassembly languageprogram for8-bitsubtractionisexecutedandthe
resultsareverified.
-
8/10/2019 mp and mc 2015
25/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 25
Fig.Flowchartfor8-bitMultiplication
-
8/10/2019 mp and mc 2015
26/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 26
EXP.NO. Date:_________
TITLE: 8-BITARITHMETICOPERATION(8-BITMULTIPLICATION)
AIM:Towriteanassembly languageprogramforthemultiplicationoftwo8-bitnumbers,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
Usingthe immediateaddressingmode instructions,thetwooperandstobemultiplied
are loaded into two registers say, B and C. By the method of repeated addition, the
multiplication operation is performed (i.e., first number is repeatedly added to
accumulator as per the second number Eg. 03 x 04=>Acc+ 03 (04 times) ). The
overflow in multiplication is checked every time after each addition, by verifying the
statusof Carry (Cy) flag andaccordinglya register,sayD is incremented.The result
inaccumulator isstored inthedesiredmemory locationandthecontentofDregister
isstored inthe locationnexttoresult.
ALGORITHM:
1. Starttheprogram.
2. CleartheAccumulatorandDRegister.
3. LoadtheData1toBregisterandData2toC register.
4. AddthecontentofBtoaccumulatoruntilC becomeszero.
5. IfNo-carry,gotostep6.
6. IncrementtheD-register.
7. DecrementtheC register.
8. IfC register isNon-zero,Jumptostep4.
9. Storethecontentofaccumulatorto5000H.
10.MovethecontentofD-registertoAccumulator.
11.Storethecontentofaccumulatorto5001H.
12.Stoptheprogram.
-
8/10/2019 mp and mc 2015
27/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 27
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4500 3E,00 MVIA,00 Movedatatoaccumulator
4502
06,Data1
MVIB,Data1
Movemultiplicandtob
register4504 0E,Data2 MVIC,Data2
Movethemultipliertocregister
4506 16,00 MVID,00 ClearD-regforcarry
4508 80 LOOP2: ADDB repetitiveaddition
4509 D2,0D,45 JNC LOOP1JumponnocarrytoanlocationLOOP1
450C 14 INR DIncrementtheD-register,ifcarryoccurs.
450D 0D LOOP1: DCR C DecrementC-register
450E C2,08,45 JNZLOOP2JumponnozerotoLocationLOOP2
4511 32,00,50 STA5000 Storeresultantproduct
4514 7A MOVA,DMovecarrytoaccumulator
4515 32,01,50 STA5001 Storethecarry.
4518 76 HLT Stoptheprogram.
MANUALCALCULATION
-
8/10/2019 mp and mc 2015
28/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 28
SAMPLEDATA:
Resultof8bitmultiplicationwithoutcarry:
INPUT OUTPUT
Address Data Address Data
4503 05H5000
(Result) 19H
4505 05H5001
(Carry) 00H
Resultof8bitmultiplicationwithcarry:
INPUT OUTPUT
Address Data Address Data
4503 41H 5000(Result) 45H
4505 25H5001
(Carry) 01H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
45035000
(Result)
45055001
(Carry)
RESULT:Thustheassembly languageprogram for8-bitmultiplicationisexecutedandthe
resultsareverified.
-
8/10/2019 mp and mc 2015
29/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 29
Fig. Flowchartfor8-bitDivision
-
8/10/2019 mp and mc 2015
30/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 30
EXP.NO. Date:_________
TITLE: 8-BITARITHMETICOPERATION (8-BITDIVISION)
AIM: Towriteanassembly languageprogram forthedivisionoftwo8bit
numbers,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
Using the immediate addressing mode instructions, the Divisor and Dividend are
loaded directly into Accumulator and B register. By the method of successive
subtraction, the division is carried out (i.e., Divisor is repeatedly subtracted from
Dividend,untilthedividendbecomessmallerthandivisor Eg.09/02=>0902(4
times) => Remainder=01 and Quotient=04). The C register is incremented every
time after each subtraction, to keep count of the quotient. The final content in
accumulator will be remainder of the division and it is stored in the desired memory
locationand thecontentofC registercontaining thequotient isstored inthe location
nexttoresult.
ALGORITHM:
1. Starttheprogram.
2. ClearC Register.
3. LoadtheDivisortoAccumulator.
4. LoadtheDividendtoB-register.
5. ComparetheB-registervaluewiththeaccumulator.
6. IfAccumulatorcontent issmallertoBreg.,thenJumptostep10.
7. SubtractB-registervaluewithaccumulator.
8. IncrementtheC-register.
9. Jumptostep4.
10.StorethecontentsofaccumulatorandC-registerintomemory.
11.Stoptheprogram.
-
8/10/2019 mp and mc 2015
31/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 31
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4500 3E,Divisor MVIA,Divisor MoveDivisortoAcc
4502 06,Dividend MVIB,Dividend MoveDividendtoBreg.
4504 0E,00 MVIC,00 ClearC register
4506 B8 LOOP2: CMPB CompareAccandBreg.
4507 DA,0F,45 JC LOOP1JumponCarrytolocationLOOP1
450A 90 SUBBRepetitivesubtractionfordivision
450B 0C INR C IncrementC register
450C C3,06,45 JMPLOOP2 Jumpto locationLOOP2
450F 32,00,50 LOOP1: STA5000 StoretheRemainder
4512 79 MOVA,C MoveC reg.toAcc
4513 32,01,50 STA5001 StoretheQuotient.
4516 76 HLT Stoptheprogram.
MANUALCALCULATION:
-
8/10/2019 mp and mc 2015
32/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 32
SAMPLEDATA:
Resultof8-bitDivisionwithoutremainder:
INPUT OUTPUT
Address Data Address Data
4501 06H 5000(R) 00H
4503 03H 5001(Q) 02H
Resultof8bitdivisionwithremainder:
INPUT OUTPUT
Address Data Address Data
4501 25H 5000(R) 02H
4503 05H 5001(Q) 07H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
4501 5000(R)
4503 5001(Q)
RESULT:
Thustheassembly languageprogram for8-bitdivision isexecutedandtheresults
areverified.
-
8/10/2019 mp and mc 2015
33/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 33
Fig. Flowchartfor16-bitAddition
-
8/10/2019 mp and mc 2015
34/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 34
EXP.NO. Date:_________
TITLE: 16-BITARITHMETICOPERATION (16-BITADDITION)
AIM:Towriteanassembly languageprogramfortheadditionoftwo16-bit
numbers,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
Using the direct addressing mode instructions, the two 16-bit numbers are loaded
into HL and DE register pairs from memory. Using the double addition instruction
(DAD rp),thecontentsofHLandDEareaddedtogetherand theresultsarestored in
theHL registerpairagain. TheB register is used tocheck theoverflowoftheabove
addition,by verifying thecarry flag.The result in theHL registerpair is stored inthe
desired memory location and the content of B register is stored in the location next
toresult.
ALGORITHM:
1. Starttheprogram.
2. CleartheB-register.
3. LoadtheData1toHLregisterpair.
4. ExchangethecontentofHLtotheDEregisterpair.
5. LoadtheData2toHLpairregister.
6. AddthecontentofHLandDEpair.
7. Ifnooverflow inaddition(nocarry),gotostep9.
8. IncrementthecontentofB-register.
9. StorethecontentofHLpairtotheaddress5504H.
10.StorethecontentofB-registertotheaddress5506H.
11.Stoptheprogram.
-
8/10/2019 mp and mc 2015
35/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 35
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4500 06,00 MVIB,00 ClearBregister
4502 2A,00,55 LHLD5500 LoadData1toHLregister
4505 EB XCHGShiftthedata inHLtoDEregister
4506 2A,02,55 LHLD5502 LoadtheData2toHLpair
4509 19 DADDAddthecontentoftheHLandDEpair
450A D2,0E,45 JNC LOOPJumponnocarrytoanaddress
450D 04 INR B IncrementtheBregister
450E 22,04,55 LOOP SHLD5504 Storetheresult
4511 78 MOVA,B MovecarrytoBregister.
4512 32,06,55 STA5506 Storethecarry.
4515 76 HLT Stoptheprogram.
MANUALCALCULATION:
-
8/10/2019 mp and mc 2015
36/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 36
SAMPLEDATA:
Resultof16-bitAdditionwithoutcarry:
INPUT OUTPUT
Address Data Address Data
5500,01 7167H 5504,05(Result) F7ECH
5502,03 8685H5506
(Carry) 00H
Resultof16-bitAdditionwithcarry:
INPUT OUTPUT
Address Data Address Data
5500,01 FF03H5504,05
(Result) 06FEH
5502,03 EF03H5506(Carry) 01H
Exercise:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data5500,01
5504,05
(Result)
5502,035506
(Carry)
RESULT:
Thustheassembly languageprogram for16-bitaddition isexecutedandtheresults
areverified.
-
8/10/2019 mp and mc 2015
37/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 37
Fig. Flowchartfor16-bitSubtraction
-
8/10/2019 mp and mc 2015
38/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 38
EXP.NO. Date:_________
TITLE: 16-BITARITHMETICOPERATION (16-BITSUBTRACTION)
AIM:Towriteanassembly languageprogramforthesubtractionoftwo16-bit
numbers,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
Using the direct addressing mode instructions, the two 16-bit numbers are loaded
into HL and DE register pairs. The lower bytes of the two numbers are subtracted
first using SUB instruction and the higher bytes of the same two numbers are
subtracted along with borrow using SBB instruction. The result in the accumulator
aftereachsubtractionisstoredinthetwosubsequentdesiredmemory locations.
ALGORITHM:
1. Starttheprogram.
2. LoadtheData2toHLregisterpair.
3. ExchangethecontentofHLtotheDEregisterpair.
4. LoadtheData1toHLregisterpair.
5. MovethecontentofLregistertoAccumulator.
6. SubtractthecontentofEregisterfrom theAccumulator.
7. Storetheresult inaccumulatortothememory location,5100H.
8. MovethecontentofHregistertoAccumulator.
9. SubtractthecontentofDregisterfromtheAccumulator,alongwithborrow.
10.Storetheresult inAccumulatortothememory location,5101H.
11.Stoptheprogram.
-
8/10/2019 mp and mc 2015
39/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 39
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4500 2A,00,55 LHLD5500LoadtheData2toHLregister.
4503 EB XCHG TransferthecontentofHLtoDEregisterpair.
4504 2A,02,55 LHLD5002LoadtheData2toHLpairregister.
4507 7D MOVA,LMovethecontentofLregistertoaccumulator
4508 93 SUBESubtractEregisterandaccumulator
4509 32,00,51 STA5100 Storetheresult
450C 7C MOVA,HMoveHregistertoaccumulator
450D 9A SBBDSubtractDregisterandaccumulator
450E 32,01,51 STA5101 Storetheresult.
4511 76 HLT Stoptheprogram.
MANUALCALCULATION:
-
8/10/2019 mp and mc 2015
40/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 40
SAMPLEDATA:
Resultof16-bitSubtraction:
INPUT OUTPUT
Address Data Address Data
5500,01(Data2) 6677H
5100(Result) 1111H
5502,03
(Data1) 7788H - -
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
5500,01
(Data2)5100
(Result)5502,03
(Data1) - -
RESULT:
Thustheassembly languageprogram for16-bitsubtractionisexecutedandthe
resultsareverified.
-
8/10/2019 mp and mc 2015
41/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 41
EXPT NO: 2(b) Program for 16 bit Arithmetic operation using 8086 DATE:
AIM:To perform basic 16 bit arithmetic operations in 8086 Microprocessor.
APPARATUS REQUIRED:
Sl.No. Apparatus required Quantity
1 8086 Microprocessor Kit 1
2 DC Power Supply 5V 1
ALGORITHM:
ADDITION:
1. Set SI register as pointer for data
2. Get the first data in AX register
3. Get the second data in BX register
4. Clear CL register
5. Get the sum in AX register
6. Store the sum in memory
7. Check for carry .If carry flag is set then go to next step,otherwise go to step-9
8. Increment CL register9. Store the carry in memory
10.Stop
SUBTRACTION:
1. Set SI register as pointer for data
2. Get the minuend in AX register
3. Get the subtrahend in BX register
4. Clear CL register to account for sign
5. Subtract the content of BX from AX ,the difference will be in AX
6. Check for carry .If carry flag is set then go to next step,otherwise go to step 9
7. Increment CL retgister by one
8. Take 2s Complement of the difference in AX register(For this complement Ax and add one.
9. Store the magnitude of difference in memory
10.Store the sign bit in memory
11.Stop
-
8/10/2019 mp and mc 2015
42/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 42
MULTIPLICATION:
1. Load the address of data in SI register
2. Get the first data in AX register
3. Get the second data in BX register
4. Multiply the content of AX and BX .The product will be in AX and DX
5. Save the product (AX and DX) in memory6. Stop
DIVISION:
1. Load the address of data in SI register
2. Get the lower word of dividend in AX register
3. Get the upper word of dividend in DX register
4. Perform division to get quotient in AX and remainder in DX
5. Save the quotient (AX) and the remainder (DX) in memory
RESULT:
Thus the Basic 16 bit arithmetic operations have been performed successfully on 8086
microprocessor by Assembly Language Programming (ALP).
-
8/10/2019 mp and mc 2015
43/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 43
Program:Add two 16-bit numbers with considering the carry.
Flow Chart
Store carry (CL register) in memory
Stop
START
Load the address of data in SI register
Get the 1st
data in AX register
Get the 2nd
data in BX register
Clear CL register
Get the sum (in AX register)
Is
=
Increment CL register
Store the sum in memor
YES
NO
-
8/10/2019 mp and mc 2015
44/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 44
Program
Address Label Mnemonics Opcode Comments
8000 MOV SI,1100H BE 81 00 Set SI register as
pointer for data
8003 MOV AX,[SI] 8B 04 Get the first data
in AX register
8005 MOV BX,[SI+2] 8B 5C 02 Get the second
data in BX
register
8008 MOV CL,00H B1 00 Clear the CL
register for carry
800A MOV AX,BX 03 C3 Add the two
data,sum will be
in AX register
800C MOV [SI+4],AX 89 44 04 Store the sum in
memory
location(1104H)
800F JNC AHEAD 73 02 Check the status
of carry flag
8011 INC CL FE C1 If carry flag is
set,increment CL
b one
8013 AHEAD MOV [SI+6],CL 88 4C 06 Store carry in
memory location
(1106H)
8016 INT 3 CC
-
8/10/2019 mp and mc 2015
45/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 45
Program:Subtract two 16-bit numbers along with considering the borrow.
Flow Chart
Stop
Increment CL register by one
Complement the content of AX
re ister
Add 01H to AX registerStore the sign bit
START
Load the address of data in SI register
Get the minuend in AX register
Get the subtrahend in BX register
Clear CL register
Subtract BX from AX
Is
CF=1?
Store the difference in memory
YES
NO
-
8/10/2019 mp and mc 2015
46/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 46
Program:
Address Label Mnemonics Opcode Comments
8000 MOV SI,1100H BE 81 00 Load the address
of data in SI
register
8003 MOV AX,[SI] 8B 04 Get the minuendin AX register
8005 MOV BX,[SI+2] 8B 5C 02 Get the
subtrahend in BX
register
8008 MOV CL,00H B1 00 Clear the CL
register to
account for sign
800A SUB AX,BX 2B C3 Get the
difference in AX
register
800C JNC STORE 73 07 Check the status
of carry flag
800E INC CL FE C1 If carry flag is set
,increment by
one
8010 NOT AX F7 D0 Take 2s
complement of
the difference
8012 ADD AX,0001H 05 00 01 Add 01H to AXregister
8015 STORE MOV[SI +4],AX 89 44 04 Store difference
in memory
location (1104H)
8018 MOV [SI+6],CL 88 4C 06 Store sign bit in
memory location
(1106H)
801B INT 3 CC
-
8/10/2019 mp and mc 2015
47/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 47
Program:Multiply two 16-bit numbers.
Flow Chart
Program:
Address Label Mnemonics Opcode Comments
8000 MOV SI,1100H BE 81 00 Load the address
of data in SI
register
8003 MOV AX,[SI] 8B 04 Get the minuend
in AX register
8005 MOV BX,[SI+2] 8B 5C 02 Get the
subtrahend in BX
register
8008 MUL BX F7 E3
800A STORE MOV[SI +4],AX 89 44 04 Store differencein memory
location (1104H)
800D MOV [SI+6],DX 89 54 06 Store sign bit in
memory location
(1106H)
8010 INT 3 CC
Load the address of data in SI register
Get the first data in AX register
Get the second data in BX re ister
Multi l the content of AX and BX
Save the lower word (AX) of product in memory
Save the upper word (DX) of product in memory
Start
Stop
-
8/10/2019 mp and mc 2015
48/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 48
Program:Division two 16-bit numbers.
Flow Chart
Program
Address Label Mnemonics Opcode Comments
8000 MOV SI,1100H BE 81 00 Load the address of
data in SI register
8003 MOV AX,[SI] 8B 04 Get the minuend in
AX register
8005 MOV DX,[SI+2] 8B 54 02 Get the subtrahend in
BX register
8008 MOVBX ,[SI +4] 8B 5C 04
800B STORE DIV BX F7 F3 Store difference in
memory location(1104H)
800D MOV [SI+6],AX 89 44 06
8010 MOV [SI+8],DX 89 54 08 Store sign bit in
memory location
(1106H)
8013 INT 3 CC
Start
Get the lower word of dividend in AX register
Save the remainder (DX) in memory
Get the upper word of dividend in DX register
Divide AX and DX with BX
Save the quotient (Ax) in memory
Stop
-
8/10/2019 mp and mc 2015
49/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 49
Result:
Addition
Sample Data Input Data: Data =F048H ----Output Data:Sum=009AH, Carry=01H
INPUT OUTPUT
Memory Address Content Memory Address Content
8100 48 8104 9A
8101 F0 8105 008102 52 8106 01
8103 10
Subtraction
Sample Data: Input Data:Minuend =840CH-----Output Data:Difference=2EBEH , Sign Bit =01H
Multiplication:
Sample Data: Input Data:Data 1=EF1AH----Output Data:BFC28A20H, Data 2 =CD50H
INPUT OUTPUT
Memory Address Content Memory Address Content
8100 1A 8104 20
8101 EF 8105 8A
8102 50 8106 C2
8103 CD 8107 BF
Division:
Sample Data: Input Data:Divident=71C2580AH,Divisor=F6F2H ,Output Data:Quotient=75EEH
Remainder=290EH
INPUT OUTPUT
Memory Address Content Memory Address Content8100 0A 8106 EE
8101 58 8107 75
8102 C2
8103 71
8104 F2 8108 0E
8105 F6 8109 29
INPUT OUTPUT
Memory Address Content Memory Address Content
8100 0C 1104 BE
8101 84 1105 2E8102 CA 1106 01
8103 B2
-
8/10/2019 mp and mc 2015
50/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 50
Fig.3.1aFlowchartforSortinginAscendingorder
-
8/10/2019 mp and mc 2015
51/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 51
EXP.NO.
TITLE: SORTINGANDSEARCHINGUSING8085-
Date:_________
SORTINGPROGRAM
AIM:Towritean assembly language program forarrangean arrayof 8-bit numbers
inascendinganddescendingorder,using8085.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
This program uses the register indirect addressing mode instructions, to access the
data during sorting. The Bubble-Sort technique is used to sort the numbers in either
ascending order or descending order. The numbers to be sorted is stored in the
memory as a array with the first location containing the count of the data in the
array. The sorted numbers are stored back again in the same source location of the
array.
(I)ALGORITHM:ASENDINGORDER:
1. Starttheprogram
2. LoadthedataaddresstoHLregisterpairandInitializeBregisterwith00
3. Movethearraysizecount intoC-register,thendecrementtheC-register
by1and incrementHLregisterpairby1.
4. LoadthefirstdatainthememorytoAccumulator.
5. ComparethesubsequentmemorywithAccumulator.
6. JumponCarry,whenM isgreaterAandgotoStep9.
7. MovethememoryM toDregister
8. DecrementtheaddressofHLpairandmovetheDregistercontenttoMand incrementthevaluebyHLby1.
9. Move01toBregisteranddecrementtheC-register.
10. IfC isNon-zero,Jumptocomparisonofnextdata.
11. IfBbecomeszeroafterdecrement,gotostep1.
11.Stoptheprogram.
-
8/10/2019 mp and mc 2015
52/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 52
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4100 06,00 AHEAD: MVIB,00 Clearthecounter
4102 21,50,41 LXIH,4150LoadDataaddrtoHLpair.
4105 4E MOVC,M MoveArraysizetoC-reg
4106 0D DCR C DecrementC reg
4107 23 INXH Incrementaddr inHL
4108 7E LOOP2: MOVA,M Movedata-I inHLtoA
4109 23 INXH Incrementaddr inHL
410A BE CMPMComparedata-IIofMemory(HL)withA
410B DA,15,41 JC LOOP1 Jumponcytoadd
410E 56 MOVD,MMovethedata inHLtoD
reg410F 77 MOVM,A
MovecontentofacctoHL.
4110 2B DCXHDecrementaddress inHLregister.
4111 72 MOVM,DMovecontentofDtoMreg
411223 INXH
IncrementaddressofHLregister
4113 06,01 MVIB,01 MovedatatoBreg
4115 0D LOOP1: DCR C DecrementC reg
4116 C2,08,41 JNZLOOP2 Jumponnozero
4119 05 DCR B DecrementBreg
411A CA,00,41 JZAHEAD Jumponzerotoahead
411D 76 HLT Stoptheprogram
-
8/10/2019 mp and mc 2015
53/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 53
SAMPLEDATA:
ResultoftheSortinginAscendingOrder
INPUT OUTPUT
Address Data Address Data4150
(ArraySize) 05H4150
(ArraySize) 05H
4151 78H 4151 25H
4152 A6H 4152 37H
4153 42H 4153 42H
4154 25H 4154 78H
4155 37H 4155 A6H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
4150
(ArraySize)4150
(ArraySize)
4151 4151
4152 4152
4153 4153
4154 4154
4155 4155
4156 4156
4157 4157
-
8/10/2019 mp and mc 2015
54/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 54
Fig. FlowchartforSortinginDescendingorder
-
8/10/2019 mp and mc 2015
55/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 55
(II)ALGORITHM:DESENDINGORDER:
1. Starttheprogram
2. LoadthedataaddresstoHLand initializeBregisterwith 00
3. MovetheArraysizecount intoC-registerthendecrementtheC-registerby
1and incrementHLby1.4. Loadthedata-I inthememory toA.
5. ComparethesubsequentmemorycontentwithA.
6. JumponNo-carry(whenM isgreaterA),gotoStep9.
7. MovethememoryM toDregister
8. DecrementthevalueofHLpairandmovetheDregistercontenttoMand
incrementthevaluebyHLby1.
9. MoveBregisteranddecrementtheC-register.
10. JumponNon-Zerotothenextcomparison.Ifzero,thendecrementBand
gotostep1.11.Stoptheprogram.
-
8/10/2019 mp and mc 2015
56/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 56
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4100 06,00 AHEAD: MVIB,00 Clearthecounter
4102 21,50,41 LXIH,4150 LoadDataaddrtoHLpair.
4105 4E MOVC,M MoveArraysizetoC-reg
4106 0D DCR C DecrementC reg
4107 23 INXH Incrementaddr inHL
4108 7E LOOP2: MOVA,M Movedata-I inHLtoA
4109 23 INXH Incrementaddr inHL
410A BE CMPMComparedata-IIofMemory(HL)withA
410B D2,15,41 JNC LOOP1 JumponNo-CarrytoLoop1
410E 56 MOVD,M Movethedata inMtoDreg410F 77 MOVM,A MovecontentofAtoM.
4110 2B DCXH Decrementaddress inHLreg.
4111 72 MOVM,D MovecontentofDreg.toM
411223 INXH IncrementAddr inHLreg
4113 06,01 MVIB,01 MovedatatoBreg
4115 0D LOOP1: DCR C DecrementC reg
4116 C2,08,41 JNZLOOP2 JumponNon-zerotoLOOP2
4119 05 DCR B DecrementBreg411A CA,00,41 JZAHEAD JumponZerotoAHEAD
411D 76 HLT Stoptheprogram
-
8/10/2019 mp and mc 2015
57/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 57
SAMPLEDATA:
ResultoftheSortinginDescendingorder:
INPUT OUTPUT
Address Data Address Data
4150
(ArraySize) 05H4150
(ArraySize) 05H
4151 78H 4151 A6H
4152 A6H 4152 78H
4153 42H 4153 42H
4154 25H 4154 37H
4155 37H 4155 25H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
4150
(ArraySize)4150
(ArraySize)
4151 4151
4152 41524153 4153
4154 4154
4155 4155
4156 4156
4157 4157
RESULT:
Thustheassembly languageprogram forsortingAscending&Descendingorder isexecutedandtheresultsareverified.
-
8/10/2019 mp and mc 2015
58/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 58
Fig. FlowChartforSearching
-
8/10/2019 mp and mc 2015
59/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 59
EXP.NO.
TITLE: SORTINGANDSEARCHINGUSING8085-
Date:__________
SEARCHINGPROGRAM
AIM:Towriteanassembly languageprogramtosearchthegivendata inanarray.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
This program uses the register indirect addressing mode instructions, to access the
data for searching a number from the array stored in the memory. The numbers to
be searched is loaded into theAccumulator and compared with the numbers of the
given array. Here again, the array has the data count stored in its first location.At
the end of searching, this program provides the information about the number of
times the given number is found in the array. The result is stored in the desired
memory location.
ALGORITHM:
1. Starttheprogram.
2. LoadthedataaddresstotheHLregisterpair.
3. Loadthedata tobesearched inAccumulator.
4. Loadthedatacountofarray intheC register.
5. InitializetheBregisterwith 00.
6. ComparethememorycontentaddressedbyHLpairwithAccumulator.
7. Ifnotequal(zero flag isset);gotostep9.
8. IncrementtheBregister.
9. IncrementtheHLregisterpair.
10.DecrementtheC registerby1andifnotzero,gotostep6.
11.StorethecontentofBregister inmemory.
12.Stoptheprogram.
-
8/10/2019 mp and mc 2015
60/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 60
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
4100 3A,50,42 LDA4250HLoaddatatobesearchedintoAcc frommemory
4103 21,51,42 LXIH,4251H Setpointerfordataarray
4106 06,00 MVIB,00H ClearBregister
4108 4E MOVC,M LoaddatacounttoC reg.
4109 23 LOOP: INXH IncrementHLreg.pair
410A BE CMPM CompareAcc&memory
410B C2,0F,41 JNZNEXTIfNotequal,goto locationNEXT
410E 04 INR B IncrementBregister
410F 0D NEXT: DCR C DecrementC register
4110 C2,09,41 JNZLOOPIfnotzero,gotolocationLOOP
4113 78 MOVA,B Movethedata fromBtoAcc
4114 32,00,42 STA4200 Storetheresult
4117 76 HLT Stoptheprogram
-
8/10/2019 mp and mc 2015
61/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 61
SAMPLEDATA:
ResultoftheSearching:
INPUT OUTPUT
Address Data Address Data
4250(Datatobesearched) 75H
4200
(Result) 02H
4251(Arraysize) 06H
Theresultshowsthenumberoftimes,
thegivennumberthatwasfound in
thearray.
4252 23H
4253 75H
4254 C1H
4255 A7H
4256 75H
4257 12H
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
4250(Datatobesearched)
4200
(Result)4251
(Arraysize)
Theresultshowsthenumberoftimes,
thegivennumberthatwasfound in
thearray.
4252
4253
4254
4255
4256
RESULT:
Thustheassembly languageprogram forsearchingthegivendata fromanarray is
executedandtheresult isverified
-
8/10/2019 mp and mc 2015
62/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 62
Fig. FlowchartforSortinginAscendingorderon8086.
-
8/10/2019 mp and mc 2015
63/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 63
EXP.NO.
TITLE: SORTINGANDSEARCHINGUSING8086-
Date:_________
SORTINGPROGRAM
AIM:Towriteanassembly languageprogramforthesorting inascendingand
Descendingorder,using8086.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8086-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
The Bubble-Sort technique is used to sort the numbers in either ascending order or
descendingorder.The numbers tobesorted isstored in thememoryas a arraywith
the first location containing the count of the data in the array. The sorted numbers
arestoredbackagain inthesamesource locationofthearray.
(I)AL
GORITHM
:AS
CEND
INGOR
DER:
1.Starttheprogram
2.MovedatatoCXregisterandmoveCXdatatoDIregister
3.Move1200to theBXregisterandmovethecontentof1200tomemoryofAX
4.ComparethecontentofAXwith1202
5.Jumponborrowtorep
6.Movethedata inmemorytoAXandmoveDatafromAXtoAI
7.AddDatatoBXregisterandgoto loop2
8.Performnooperationandmovedata&DItoCX
9.Gotothe loop10.Stoptheprogram
-
8/10/2019 mp and mc 2015
64/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 64
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
1000 B9,07,00 MOVCX,07 MovedatatoCXreg
1003 89CF LOOP1: MOVDI,CX MoveCXdatatoDI
1005 BB,00,12 MOVBX,1200 Move1200totheBXreg
1008 8B,07 LOOP2: MOVAX,AI[BX]Movethecontentof1200tomemoryofAX
100A 3B,47,02CMP
AX,AI[BX+2]ComparethecontentofAXwith1202H
100D 72,05 JBREP Jumponborrowtorep
100F 87,47,02XCHG
AX,AI[BX+2]Movethedata inmemorytoAX
1012 89,07 MOVAI[BX],AX MovedatafromAXtoAI
101A 83,C3,02 REP: ADDBX,02 AdddatatoBXregister
1017 F2,EF LOOPLOOP2 Goto loop2
1019 90 NOP Nooperation
101A 89,F9 MOVCX,DI MovedataofDItoCX
101C E2,E5 LOOPLOOP1 Goto loop1
101E F4 HLT Stoptheprocess
-
8/10/2019 mp and mc 2015
65/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 65
SAMPLEDATA:
ResultofSortinginAscendingorder:
INPUT OUTPUT
Address Data Address Data
1100 00FFH 1100 00CCH
1102 0100H 1102 00FEH
1104 1101H 1104 00FFH
1106 00FEH 1106 0100H
1108 00CCH 1108 1101H
110A CDEFH 110A 1234H
110C ABCDH 110C ABCDH
110E 1234H 110E CDEFH
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
1100 1100
1102 11021104 1104
1106 1106
1108 1108
110A 110A
110C 110C
110E 110E
-
8/10/2019 mp and mc 2015
66/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 66
Fig. FlowchartforSortinginDescendingorderon8086.
-
8/10/2019 mp and mc 2015
67/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 67
(II)ALGORITHM:DESCENDINGORDER
1.Starttheprogram.
2.MovethedatatoCXregisterandmoveCXcontenttoD1register.
3.MovetheaddresstoBXregisterandmovethecountof1200toAX.
4.ComparethecontentofAXwith1202.5.JumponnoborrowtoREP.
6.ExchangeAXandA1registerandmoveAXregistertoBX.
7.AddBXregisterto2andcontinuethe loopuptoCXiszero.
8.PerformnooperationandmoveD1registertoCXregisterandcontinue
the loopuptoCXiszero.
9.Stoptheprogram.
-
8/10/2019 mp and mc 2015
68/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 68
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
1000 B9,07,00 MOVCX,07 MovedatatoCXreg
1003 89CF LOOP1: MOVDI,CX MoveCXdatatoDI
1005 BB,00,12 MOVBX,1200 Move1200totheBXreg
1008 8B,07 LOOP2: MOVAX,AI[BX]Movethecontentof1200tomemoryofAX
100A 3B,47,02CMPAX,AI[BX+2]
ComparethecontentofAXwith1202H
100D 72,05 JNBREP JumponNo-borrowtoREP
100F 87,47,02XCHG
AX,AI[BX+2]Movethedata inmemorytoAX
1012 89,07 MOVAI[BX],AX MovedatafromAXtoAI
101A 83,C3,02 REP: ADDBX,02 AdddatatoBXregister
1017 F2,EF LOOPLOOP2 GotoLOOP2
1019 90 NOP Nooperation
101A 89,F9 MOVCX,DI MovedataofDItoCX
101C E2,E5 LOOPLOOP1 GotoLOOP1
101E F4 HLT Stoptheprocess
-
8/10/2019 mp and mc 2015
69/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 69
SAMPLEDATA:
ResultofSortinginDescendingorder:
INPUT OUTPUT
Address Data Address Data
1100 00FFH 1100 CDEFH
1102 0100H 1102 ABCDH
1104 1101H 1104 1234H
1106 00FEH 1106 1101H
1108 00CCH 1108 0100H
110A CDEFH 110A 00FFH
110C ABCDH 110C 00FEH
110E 1234H 110E 00CCH
EXERCISE:
Executetheprogramwithyourowndataandobservetheresults.Checktheresult
withyourmanualcalculation.
INPUT OUTPUT
Address Data Address Data
1100 1100
1102 1102
1104 1104
1106 1106
1108 1108
110A 110A
110C 110C
110E 110E
RESULT:
Thustheassembly languageprograms forsorting-ascending&descendingorderwas
executedareverified.
-
8/10/2019 mp and mc 2015
70/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 70
EXPT NO: 3(b) Program for sorting and searching using 8086 DATE:
AIMTo search a number (largest, smallest) and Sorting (Ascending and Descending) of an array
using 8086.
APPARATUS REQUIRED:
Sl.No. Apparatus required Quantity
1 8086 Microprocessor Kit 1
2 DC Power Supply 5V 1
ALGORITHM
SEARCHING
SMALLEST ELEMENT IN AN ARRAY
1. Load the starting address of the array in SI register
2. Load the address of the result in DI register
3. Load the number of bytes in the array in CL register
4. Increment the array pointer(SI register)
5. Get the first byte of the array in AL register.
6. Decrement the byte count(CL register)
7. Increment the array pointer(SI register)
8. Get next byte of the array in BL register.
9. Compare current smallest (AL) and next byte (BL) of the array.
10.Move BL to AL
11.Decrement the byte count (CL register)
12.Check zero flag.If zero flag is reset then go to step-7,otherwise go to next step.13.Save the smallest data in memory pointed by DI
14.Stop
LARGEST ELEMENT IN AN ARRAY
1. Load the starting address of the array in SI register
2. Load the address of the result in DI register
3. Load the number of bytes in the array in CL register
4. Increment the array pointer(SI register)
5. Get the first byte of the array in AL register.
6. Decrement the byte count(CL register)
7. Increment the array pointer(SI register)
8. Get next byte of the array in BL register.
9. Compare current largest (AL) and next byte (BL) of the array.
10.Move BL to AL
11.Decrement the byte count (CL register)
-
8/10/2019 mp and mc 2015
71/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 71
12.Check zero flag.If zero flag is reset then go to step-7,otherwise go to next step.
13.Save the largest data in memory pointed by DI
14.Stop
ASCENDING ORDERIN AN ARRAY
1. Set SI register as pointer for array
2. Set CL register as count for N-1 repeatitions3. Initialize array pointer
4. Set CH as count for N-1 comparisions
5. Increment the array pointer
6. Get an element of array in AL register
7. Increment the array pointer
8. Compare the next element of the array with AL.
9. Check carry flag.If carry flag is set then go to step-12,otherwise go to next step.
10.Exchange the content of memory pointed by SI and the content of previous memory location
for this,exchange AL and memory pointed by SI,and then exchange AL and memory pointed
by SI-1
11.Decrement the count for comparisions(CH register)
12.Check zero flag .If zero flag is reset then go to step-6,otherwise go to next step
13.Decrement the count for repeatitions (CL register)
14.Check zero flag .If zero flag is reset then go to step-3,otherwise go to next step
15.Stop
DESCENDING ORDER IN AN ARRAY
1. Set SI register as pointer for array
2. Set CL register as count for N-1 repetitions3. Initialize array pointer
4. Set CH as count for N-1 comparisions
5. Increment the array pointer
6. Get an element of array in AL register
7. Increment the array pointer
8. Compare the next element of the array with AL.
9. Check carry flag.If carry flag is reset then go to step-12,otherwise go to next step.
10.Exchange the content of memory pointed by SI and the content of previous memory location
(for this,exchange AL and memory pointed by SI,and then exchange AL and memory
pointed by SI-111.Decrement the count for comparisions(CH register)
12.Check zero flag .If zero flag is reset then go to step-6,otherwise go to next step
13.Decrement the count for repetitions (CL register)
14.Check zero flag .If zero flag is reset then go to step-3,otherwise go to next step
15.Stop
-
8/10/2019 mp and mc 2015
72/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 72
SMALLEST ELEMENT IN AN ARRAY
Flow Chart
Load the address of array in SI register
and address of given data in DI register
Load the address of result in DI register
Compare AL and DL register
Set CL as byte count
Increment array pointer(SI)
Start
Get the first byte of array in AL register
Decrement the b te count
Increment array pointer(SI)
Get the next byte of array in BL register
Is
CF=1?
Move BL to AL
Decrement byte count (CL)
Is
ZF=1?
Store AL in memory
Stop
YES
YES
NO
NO
-
8/10/2019 mp and mc 2015
73/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 73
PROGRAM:
Address Label Mnemonics Opcode Comments
8000 START MOV SI,1100 BE 11 00 Set SI register as
pointer for array
8003 MOV DI,1200 BF 12 00 Set DI register as
pointer for result
8006 MOV CL,[SI] 8A 0C Set CL as count for
elements in the array
8008 AGAIN INC SI 46 Increment the address
pointer
8009 MOV AL,[SI] 8A 04 Set first data as
Smallest
800B DEC CL FE C9 Decrement the count
800D INC SI 46 Make SI to point tonext data in array
800E MOV BL,[SI] 8A 1C Get the next data in
BL register
8010 CMP AL,BL 3A C3 Compare current
smallest data in AL
with BL
8012 JC AHEAD 72 02 If carry is set then AL
is less than BL hence
proceed to AHEAD8014 MOV AL,BL 8A C3 If carry is not set then
make BL as current
smallest
8016 AHEAD DEC CL FE C9 Decrement the count
8018 JNZ AGAIN 75 F3 If count is not zero
repeat search
801A MOV [DI],AL 88 05 Store the smallest data
in memory
801C INT 3 F4
-
8/10/2019 mp and mc 2015
74/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 74
LARGEST ELEMENT IN AN ARRAY
FLOW CHART
Set SI register as array pointer
Set DI register as array pointer
Compare AL and DL register
Set CL as byte count
Increment arra ointer SI
Get the first byte of array in AL register
Decrement the byte count
Increment arra ointer SI
Get the next b te of arra in BL re ister
Is
CF=0?
Move BL to AL
Decrement byte count (CL)
Is
ZF=1?
Store AL in memory
Stop
Start
Yes
NO
NO
Yes
-
8/10/2019 mp and mc 2015
75/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 75
PROGRAM:
Address Label Mnemonics Opcode Comments
8000 START MOV SI,1100 BE 11 00 Set SI register as
pointer for array
8003 MOV DI,1200 BF 12 00 Set DI register as
pointer for result
8006 MOV CL,[SI] 8A 0C Set CL as count for
elements in the array
8008 AGAIN INC SI 46 Increment the address
pointer
8009 MOV AL,[SI] 8A 04 Set first data as largest
800B DEC CL FE C9 Decrement the count
800D INC SI 46 Make SI to point tonext data in array
800E MOV BL,[SI] 8A 1C Get the next data in
BL register
8010 CMP AL,BL 3A C3 Compare current
largest data in AL
with BL
8012 JNC AHEAD 73 02 If carry is set then AL
is greater than BL
hence proceed toAHEAD
8014 MOV AL,BL 8A C3 If carry is not set then
make BL as current
largest
8016 AHEAD DEC CL FE C9 Decrement the count
8018 JNZ AGAIN 75 F3 If count is not zero
repeat search
801A MOV [DI],AL 88 05 Store the largest data
in memory
801C INT 3 F4
-
8/10/2019 mp and mc 2015
76/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 76
ASCENDING ORDER IN AN ARRAY
FLOW CHART
Yes
No
Load the address of the array in SI register
Load the count in CL re ister and decrement b one
Com are next element of arra with AL
Load the address of array in SI register
Load the count in CH re ister and decrement b one
Increment the array pointer (SI)
Get an element of array pointer(SI)
Increment the arra ointer SI
Is
CF=1?
Exchange AL and memory pointed by SI
Exchange AL and memory pointed by (SI-1)
Is
ZF=1?
Decrement CL count
Stop
Decrement CH count
Is
ZF=1?
Start
No
Yes
-
8/10/2019 mp and mc 2015
77/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 77
PROGRAM:
Address Label Mnemonics Opcode Comments
8000 START MOV SI,1100 BE 11 00 Set SI register as
pointer for array
8003 MOV CL,[SI] 8A 0C Set CL as count for N-1
repeatitions8005 DEC CL FE C9 Decrement the count
8007 REPEAT MOV SI,1100 BE 11 00 Intialize pointer
800A MOV CH,[SI] 8A 2C Set Ch as count for N-1
comparisions
800C DEC CH FE CD
800E INC SI 46 Increment the pointer
800F REPCOM MOV AL,[SI] 8A 04 Get an element of array
in AL register
8011 INC SI 46
8012 CMP AL,[SI] 3A 04 Compare with next
element of array inmemory
8014 JC AHEAD 72 05 If AL is less thanmemory ,then go to
AHEAD
8016 XCHG AL,[SI] 86 04 If AL is lesser than
memory then exchangethe content of memorypointed by SI and the
previous memory
location
8018 XCHG AL,[SI-1] 86 44 FF
801B DCE CH FE CD Decrement the count fo
comparisions
801D JNZ REPCOM 75 F0 Repeat comparision
until CH count is zero
801F AHEAD DEC CH FE C9 Decrement the count fo
repeatitions8021 JNZ REPEAT 75 E4 Repeat N-1
comparisions until CLcount is zero
8023 INT 3 F4
-
8/10/2019 mp and mc 2015
78/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 78
DESCENDING ORDER IN AN ARRAY
FLOW CHARTLoad the address of the array in SI register
Load the count in CL register and decrement by one
Com are next element of arra with AL
Load the address of array in SI register
Load the count in CH re ister and decrement b one
Increment the array pointer (SI)
Get an element of arra ointer SI
Increment the arra ointer SI
Is
CF=0?
Exchange AL and memory pointed by SI
Exchange AL and memory pointed by (SI-1)
Is
ZF=1?
Decrement CL count
Decrement CH count
Is
ZF=1?
Start
Sto
No
Yes
No
Yes
Yes
No
-
8/10/2019 mp and mc 2015
79/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 79
PROGRAM:
Address Label Mnemonics Opcode Comments
8000 START MOV SI,1100 BE 11 00 Set SI register as
pointer for array
8003 MOV CL,[SI] 8A 0C Set CL as count for N-1
repeatitions8005 DEC CL FE C9 Decrement the count
8007 REPEAT MOV SI,1100 BE 11 00 Intialize pointer
800A MOV CH,[SI] 8A 2C Set Ch as count for N-1
comparisions
800C DEC CH FE CD
800E INC SI 46 Increment the pointer
800F REPCOM MOV AL,[SI] 8A 04 Get an element of array
in AL register
8011 INC SI 46
8012 CMP AL,[SI] 3A 04 Compare with next
element of array inmemory
8014 JNC AHEAD 73 05 If AL is less thanmemory ,then go to
AHEAD
8016 XCHG AL,[SI] 86 04 If AL is lesser than
memory then exchangethe content of memorypointed by SI and the
previous memory
location
8018 XCHG AL,[SI-1] 86 44 FF
801B DCE CH FE CD Decrement the count fo
comparisions
801D JNZ REPCOM 75 F0 Repeat comparision
until CH count is zero
801F AHEAD DEC CL FE C9 Decrement the count fo
repeatitions8021 JNZ REPEAT 75 E4 Repeat N-1
comparisions until CLcount is zero
8023 INT 3 F4
-
8/10/2019 mp and mc 2015
80/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 80
Result:
Smallest from an array
INPUT OUTPUT
Address Data Address Data
8100 H:
8200 H:
8101 H:
8102 H:8103 H:
8104 H:
8105 H:
8106 H:
Largest from an array
INPUT OUTPUT
Address Data Address Data
8100 H:
8200 H:
8101 H:
8102 H:
8103 H:8104 H:
8105 H:
8106 H:
Sort the array in ascending order
INPUT OUTPUT
Address Data Address Data
1100 H:
1101 H:1101 H:
1102 H: 1102 H:
1103 H: 1103 H:
1104 H: 1104 H:
1105 H: 1105 H:
1106 H: 1106 H:
1107 H: 1107 H:
Sort the array in descending order
INPUT OUTPUT
Address Data Address Data
1100 H:
1101 H:1101 H:1102 H: 1102 H:
1103 H: 1103 H:
1104 H: 1104 H:
1105 H: 1105 H:
1106 H: 1106 H:
1107 H: 1107 H:
-
8/10/2019 mp and mc 2015
81/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 81
Fig.FlowchartforStringManipulation
-
8/10/2019 mp and mc 2015
82/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 82
EXP.NO.
TITLE:
Date:_________
STRINGMANIPULATIONUSING8086
AIM: Towriteanassembly languageprogramtomoveabyteofstringoflengthFF
fromasourcetoadestination.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8086-microprocessorkit. 1
2 Powersupplyunit 1
THEORY:
A group of similar data stored in consecutive memory locations, representing a
variablecanbecelledas a String. Variousoperationscanbeperformedonthestring
data like, string copy, string compare, string store, string load, etc. The following
programhelpstocopyastringdata fromasourcelocationtoadestination location.
ALGORITHM:
1. Starttheprogram.2. SettheSItopointthesourcearrayandDIatdestination location.
3. MovethestringsizetoCXregister.
4. DirectionFlag isclearedsothatSI&DIwillautoincrementaftereach loop.
5. MovethebytesofthestringusingMOVSB instruction.
6. Stop
-
8/10/2019 mp and mc 2015
83/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 83
PROGRAM:
AddressOpcode&Operand Label Mnemonics Comments
1000 BE,00,11 MOVSI,SourceLoadoffsetaddressofSourcetoSIregister
1003 BF,00,12 MOVDI, DestinationLoadoffsetaddressof
destinationtoDIregister1006 B9,FF,00 MOVCX,00FFH
NumberofarrayelementsinCXregister
1009 FC CLD ClearDirectionFlag(D)
100A A4 NEXT: MOVSB Movestringbyte
100B E2,FD LOOPNEXTDecrementCXandCheck
forZero.Ifnotzero,goto locationNEXT
100D F4 HLT Stoptheprogram
-
8/10/2019 mp and mc 2015
84/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 84
SAMPLEDATA:
ResultofStringmanipulation:
INPUT(Source) OUTPUT(Destination)
Address Data Address Data
1100 xx 1200 xx
To xx To xx
11FF xx 12FF xx
AsCXRegisteris loadedwithstringsize FF
256bytesofdataatsource location
(starting from1100H)willbecopiedtodestination location
(at address1200H)
EXERCISE:
ResultofStringmanipulation:
INPUT(Source) OUTPUT(Destination)
Address Data Address Data
1100 1200
1101 1201
1102 1202
1103 1203
1104 1204
1105 1205
1106 12061107 1207
1108 1208
Executetheprogramwithfollowingmodifications.
a) Move smaller sized string data, by changing the string size stored in CX
register.
b) Change the auto-increment of SI & DI registers toauto-decrement bysetting
the direction flag to 1.Also store the last address of the string in SI & DI
register insteadofstartingaddressofthestring.
RESULT:
Thusthestringwasmovedfromsourcetodestinationusingtheassemblylanguage
of8086.
-
8/10/2019 mp and mc 2015
85/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 85
FlowChart:
PROGRAM(16-bitAddition):
AddressOpcode&Operand Label Mnemonics Comments
4100 C3 CLR C Clearcarry
4101 74,Data1L MOVA,#DATA1 MoveData1LtoAcc
4103 24,Data2L ADDA,#DATA2 AddData2LwithAcc
4105 90,41,50MOVDPTR,#4150h
Movecontent in4500toDPTR.
4108 F0 MOVX@DPTR,A MovedatatoDPTR location
4109 A3 INC DPTR IncrementDPTR
410A 74,Data1H MOVA,#DATA1 MoveData1HtoAcc
410C 34,Data2HADDC A,#DATA2 AddAccwithData2H&Carry
410E F0 MOVX@DPTR,AMovefromAcctoDPTR location
410F 80,FE HERE: SJMPHERE End
-
8/10/2019 mp and mc 2015
86/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 86
EXP.NO: Date:_________
TITLE: PROGRAMMINGARITHMETIC,LOGICALAND
BITMANIPULATIONUSING8051
AIM: To write an assembly language program for the arithmetic, logical and bit
manipulationusing8051.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8051MicroControllerkit. 1
2 PowerSupplyunit 1
(A)ARITHMETICOPERATION:
(I)16BITADDITION:
ALGORITHM:
1.Starttheprogram.
2.GettheLSBof1st
and2nd
operands.
3.AddtheLSBofthetwooperandsandstoreit inmemory.
4.GettheMSBof1st
and2ndoperands.
5.AddtheMSBandstoretheresult inmemory
6.Stoptheprogram.
OUTPUTOF16-BITADDITION:
INPUT OUTPUT
Address Data Address Data
4102 4500
4104 4501410B - -
410D - -
-
8/10/2019 mp and mc 2015
87/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 87
FlowChart:
PROGRAM(8-bitSubtraction):
AddressOpcode&Operand Label Mnemonics Comments
4100 C3 CLR C Clearcarry
4101 74,Data1 MOVA,#DATA1 Movedata1toacc
4103 94,Data2 SUBBA,#DATA2 Adddata2withacc
4105 90,45,00MOVDPTR,
#4500hMove4500toDPTR.
4108 FO MOVX@DPTR,AMoveAccvaluetoDPTRlocation
4109 80,FE HERE: SJMPHERE End
-
8/10/2019 mp and mc 2015
88/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 88
(II)8-BITSUBTRACTION:
ALGORITHM:
1. Starttheprogram.
2. Clearthecarryflagand loadthe firstoperand inaccumulator.
3. Getthe2nd
operandandsubtract it fromaccumulator.
4. Storetheresult inmemory.
5. Stoptheprogram.
OUTPUTOF8-BITSubtractionwithoutCarry:
INPUT OUTPUT
Address Data Address Data
4102 4500
4104 - -
-
8/10/2019 mp and mc 2015
89/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 89
FlowChart:
PROGRAM(8-bitMultiplication):
AddressOpcode&
OperandLabel Mnemonics Comments
4100 74,Data1 MOVA,#DATA1 MoveData1 toAcc
4102 75,F0,Data2 MOVB,#DATA2 MoveData2 toAcc
4105 A4 MULAB MultiplyAccandB
4106 90,45,00MOVDPTR,#4500h Move4500toDPTR.
4109 FO MOVX@DPTR,AMoveAccvaluetoDPTR
location
410A A3 INC DPTR INC DPTR
410B E5,F0 MOVA,BMoveBregistervalueto
Acc410D FO MOVX@DPTR,A
MoveAccvaluetoDPTRlocation
410E 80,FE HERE: SJMPHERE End
-
8/10/2019 mp and mc 2015
90/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 90
(III)8-BITMULTIPLICATION:
ALGORITHM:
1. Starttheprogram.
2. Loadthe1st operand inAand2
ndoperand inB.
3. MultiplyAandBcontentsusingMUL instruction.4. Storetheresult inmemory.
5. Stoptheprogram.
OUTPUTOF8-BITMultiplication:
INPUT OUTPUT
Address Data Address Data
4101 4500
4104 4501
-
8/10/2019 mp and mc 2015
91/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 91
FlowChart:
PROGRAM(8-BitDivision):
AddressOpcode&Operand Label Mnemonics Comments
4100 74,Data1 MOVA,#DATA1 MoveDividendtoAcc
4102 75,F0,Data2 MOVB,#DATA1 MoveDivisortoB
4105 84 DIVAB DivideAbyB
4106 90,45,00MOVDPTR,#4500h Move4500toDPTR.
4109 FO MOVX@DPTR,AMoveAccvaluetoDPTRlocation
410A A3 INC DPTR IncrementDPTR
410B E5,F0 MOVA,B MoveB-reg.valuetoAcc
410D FO MOVX@DPTR,A Storetheresult
410E 80,FE HERE: SJMPHERE End
-
8/10/2019 mp and mc 2015
92/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 92
(IV)8BITDIVISION:
ALGORITHM:
1. Starttheprogram.
2. Get1st operand inAand2
ndinB.
3. DivideAbyBcontentsusingdivision instruction.4. Storetheresult inmemory.
5. Stoptheprogram.
OUTPUTOF8-BITDivision:
INPUT OUTPUT
Address Data Address Data
41014500
(Quotient)
4104 4501(Remainder)
-
8/10/2019 mp and mc 2015
93/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 93
FlowChart:
PROGRAM(OR):
AddressOpcode&Operand Label Mnemonics Comments
4100 74,Data1 MOVA,#DATA1 MoveData1 toAcc
4102 44,Data2 ORLA,#DATA2 ORAccandData2
4104 90,45,00MOVDPTR,#4500H Move4500toDPTR.
4107F
O MOVX@DP
TR,A Storetheresult4108 80,FE HERE SJMPHERE End
-
8/10/2019 mp and mc 2015
94/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 94
(B)LOGICALOPERATION:
(I) OROPERATION:
ALGORITHM:
1. Starttheprogram.
2. Load1st
operand inAccumulator.
3. Get2nd
operandandperformOR betweenAccand2nd
Operand.
4. Storetheresult inmemory.
5. Stoptheprogram.
OUTPUTOFOROperation:
INPUT OUTPUT
Address Data Address Data4101 4500
4103 - -
-
8/10/2019 mp and mc 2015
95/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 95
FlowChart:
PROGRAM(AND):
AddressOpcode&Operand Label Mnemonics Comments
4100 74,Data1 MOVA,#DATA1 MoveData1 toAcc
4102 54,Data2 ADLA,#DATA2 ANDAccandData2
4104 90,45,00MOVDPTR,#4500H Move4500toDPTR.
4107 FO MOVX@DPTR,A Storetheresult
4108 80,FE HERE: SJMPHERE End
-
8/10/2019 mp and mc 2015
96/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 96
(II)ANDOPERATION:
ALGORITHM:
1. Starttheprogram.
2. Get1st operand inAccumulator.
3. Get2nd
operandandperformANDaccumulatorcontent&2nd
operand
4. Storetheresult inmemory.5. Stoptheprogram.
OUTPUTOFANDOperation:
INPUT OUTPUT
Address Data Address Data
4101 4500
4103 - -
RESULT:
Thustheprograms involvingarithmetic, logicalandbitmanipulationusing8051are
executedand itsresultsareverified.
-
8/10/2019 mp and mc 2015
97/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 97
Fig. BlockdiagramofADCconversion
-
8/10/2019 mp and mc 2015
98/150
PSNCET MICROPROCESSOR ND MICROCONTROLLER L B M NU L
Page 98
EXP.NO.
TITLE:
INTERFACING ADC AND DAC USING 8085 Date:_________
AIM: Towriteanassembly languageprogramto interfaceADC andDAC with8085microprocessorkit.
APPARATUSREQUIRED:
S.No ItemDescription Qty
1 8085-microprocessorkit. 1
2 CRO 1
3 ADC &DAC interfaceboard 14 FlatribbonCable 1
THEORY:
In a real time applications, processing of input data, conversion of data from digital
to analog and vice versa, are indispensable. The following program initiates the
analog to digital conversion process, checks theEOC pin ofADC 0809 as to whether
theconversion isoverand then inputs thedata to theprocessor.Italso instructs the
processortostoretheconverteddigitaldata inthememory.
ADC:
HARDWAREDETAILS:
ADC 0809 isamonolithicCMOSdevice,withan8-bitanalog-to-digitalconverter,8
channelmultiplexerandmicroprocessorcompatiblecontrol logic.
SelectedAnalogChannel
AddressLinesintheMultiplexerofADC 0809AddrC AddrB AddrA
IN0 0 0 0IN1 0 0 1IN2 0 1 0IN3 0 1 1IN4 1 0 0IN5 1 0 1
IN6 1 1 0IN7 1 1 1
Aparticular inputchannel isselecte