You are on page 1of 5

11/08/2016

HelpingTutorial:8086microprocessorProgramming(Part1)
0

More NextBlog

CreateBlog SignIn

HelpingTutorial
Home

Tutorials

Adsby Google

Download

Math

KeyProgramming

ProgrammingCode

ProgrammingArm

ProgrammingVideo

Friday,25January2013

8086microprocessorProgramming(Part1)
INTRODUCTIONTOASSEMBLYLANGUAGE
PROGRAMMING
AimsoftheExperiment:
Giveanintroductiontothearchitectureof8086microprocessor
EnablethestudentstowritesmallassemblylanguageprogramsusingDEBUGutility
program.
Search

Introduction:
Assemblylanguageprogramsresembleacompiledlanguageprograms,likePASCAL.Incompiled
languagestheuserfirstcreatesasourcefile,whichisatextfileofentireprogram.Thecompiler
changesitintomachinelanguageinstructions.(Actuallyalinkerisusedtoobutisignoredforthe
time being) In the compiled language program the entire program is transformed into machine
languageatonce.
Someofthemostrudimentaryfunctionsthatadebuggercanperformarethefollowing:
Assembleshortprograms
Viewaprogramssourcecode,alongwithitsmachinecode
ViewtheCPUregistersandflags
Traceorexecuteaprogram,watchingvariablesforchanges
Enternewvaluesintomemory
SearchforbinaryorASCIIvaluesinmemory
Moveablockofmemoryfromonelocationtoanother
Fillablockofmemory
Loadandwritediskfiles

DEBUGcommands:
WellbeusingonlysomeoftheDEBUGcommandsinthisexperiment.Ifyouwanttohavealook
at the entire commandset, you can enter HELP DEBUG at the DOS prompt on your PC, if it
hashelpavailable.Themeaningofsomeofthefollowingcommandsmightbecomecleartoyou
laterduringthisexperiment.
A

Assembleaprogramusinginstructionmnemonics

Executetheprogramcurrentlyinthememory

Displaythecontentsofregistersandflags

Traceasingleinstruction

Disassemblememoryintoassemblermnemonics

Dump(display)thecontentsofmemory

Enterbytesintomemory

Fillamemoryrangewithasinglevalue

QuitDEBUGandreturntoDOS

Loaddatafromdisk

Writedatafrommemorytodisk

CreateafilenameforusebytheLandWcommands

http://helpingtutorial.blogspot.in/2013/01/8086microprocessorprogrammingpart1.html

PopularPosts

8086microprocessorProgramming(Part1)
INTRODUCTIONTOASSEMBLY
LANGUAGEPROGRAMMINGAimsofthe
Experiment:Giveanintroductiontothe
architectureof8086microprocessor
Enable...
8086microprocessorProgramming(Part4)
WORKINGWITHDATATRANSFERAND
ARITHMETICINSTRUCTIONSAimsofthe
Experiment:Giveanintroductiontotheuse
ofMicrosoftMacroAssembler...
8086microprocessorProgramming(Part8)
ADJUSTMENTINSTRUCTION
OBJECTIVES:Tostudythe8086instruction
forASCIIanddecimaladjustmentfor
additionandsubtraction.Tostudythe...
UltraSmallPenSpy
Camera
UltraSmallPenSpy
CameraThebestSpy
CameraPenneedstobe
undetectable,totally
reliable,andcapableofdeliveringgreat
videoandaud...
TIMERandCOUNTER
PROGRAMMING
Timers/Counters
ProgrammingThe8051has
twotimers/counters,they
canbeusedeitheras
TimerstogenerateatimedelayorasEvent
counter...
JUMP,LOOPANDCALLINSTRUCTIONS
loop:Repeatingasequenceofinstructions
acertainnumberoftimesiscalledaloop
LoopactionisperformedbyDJNZreg,
LabelTheregist...
LEDChaserusingParallel
Port
LEDChaserusingParallel
PortInthistutorialyouwill
learnaboutconnectionsto
parallelportandAssemblyLanguage

1/5

11/08/2016

HelpingTutorial:8086microprocessorProgramming(Part1)

The8086Registers
Registers are special work areas inside the microprocessor designed to be accessed at high
speeds. The registers are 16 bits long but you have the option of accessing the upper or lower
halvesofthefourdataregisters.Againinthisexperimentwellrestrictourselvesonlytotheuse
ofdataregisters,sodontgetupsetifyoudonotunderstandthemeaningofsomeofthefollowing
registers:
DataRegisters:
16bitAX(accumulator),BX(base),CX(counter),DX(data)
8bit:AH,AL,BH,BL,CH,CL,DH,DL
SegmentRegisters:
CS(codesegment),DS(datasegment)
IndexRegisters:
SI(sourceindex),DI(destinationindex),BP(basepointer)

parallelportandAssemblyLanguage
Programmingofmicro...
SERIALCOMMUNICATION
SERIALCOMMUNICATION
BASICSOFSERIAL
COMMUNICATION:
Computerstransferdatain
twoways:ParallelOften8
ormorelines(wireconductors)a...
SevenSegmentDisplay
withParallelPort
InterfacingSevenSegment
DisplaywithParallelPort
Thisisbasicalysortof
assignmentforyoutowrite
codeforsevensegmentdisplay.I...
8086microprocessorProgramming(Part2)
THE8086ADDRESSINGMODESAimsof
theExperiment:Giveanintroductiontothe
differentaddressingmodesavailableinthe
8086microprocess...

SpecialRegisters:
IP(instructionpointer),SP(stackpointer)
FlagRegister:
Overflow,Direction,Interrupt,Trap,Sign,Zero,AuxiliaryCarry,Parity,Carry

BlogArchive

2013(82)
March(2)
February(39)
January(41)

IBMPCMemoryArchitecture:

KaprekarNumber6174Theory

The IBM PC can access 1 MB of memory using a standard 20bit address. The memory is
dividedbetweenRAMandROM.RAMmemorystartsatlocation00000handextendstoBFFFFh.
ROMmemorybeginsatlocationC0000handextendstoFFFFFh.
TheRAMarea(from00000htoBFFFFh)isfurtherdividedintofollowingparts:

AngelNumber421

Interruptvectortable
BIOSandDOSdata
ResidentpotionofRAM
UserRAM
EGAcolorvideo
Monochromevideo
Colorvideo

MultiplyingTwodigitNumbersBy11
MathAdditionTrickforAddingTwoDigit
Numbers
FingerMultiplicationofNinth(9th)Time
Table
FingerMultiplicationof6,7,8,9,10Time
Tables
MathsTrickswithNumbers
MathsMagicConsecutiveNumberFun
Tricks
MathMagicTricksBirthdayDate
Calcualtion

WellbeusingonlytheuserRAMforourprograms,whichextendsfromnearly22400htoBFFFFh
ina640KRAMmachine(nearly540K).
Caution:Donottrytowritedatatoanyotheraddressotherthanintherange22400htoBFFFFh,
otherwiseyoursystemmighthalt.

MathMagic/PhoneNumber/Missing
Digit/Funny...

ImportantNotes

NamesforPowersof10

MemoryDump(ordisplay)Command

MathMagic/Numberfun/MathsTricks
MathMagic/Tricks

Number2519
AmazingPrimeNumbers

Thiscommandisusedtodisplaymemoryonthescreenassinglebytesinbothhexadecimaland
ASCII.EnterthefollowingcommandattheDEBUGprompt:
D100
Youllseeeightlinescontainingdifferentcharactersonyourscreen.Notedownthefirstline.The
numbers in the left column will be in segment: offset format. The number in second column that
you noted down displays the contents of memory at offset 0100h, the number in third column
displays the contents of 0101h, and so on the number in 17th column displays the contents of
memory at offset address 010Fh. (The characters to the right are the ASCII representation of
each byte.) Calculate the absolute address corresponding to this last memory location. Refer to
appendixnotesB,ifyouhavenotbeenthroughthem.
Nowdisplay(ordump)thememorycontentswithintherangeofoffsetaddresses140hand14Bh.
Notedownthecommandthatyouuse.
Tryfollowingcommandsaswellandnotedownyourobservationsontheworksheet:
D4411:0
D1001:20
MemoryFillCommand

BeautyofMathematics
AgeCalculation
DayoftheDate
SERIALCOMMUNICATION
TIMERandCOUNTERPROGRAMMING
ARITHMETIC&LOGICINSTRUCTIONS
ANDPROGRAMS
ADDRESSINGMODES
I/OPROGRAMMING
JUMP,LOOPANDCALL
INSTRUCTIONS
FlagRegister
MyFirstProgramInAssemblyLanguage
IntroductiontoAssemblyLanguage
Programming
IntroductiontoMicrocontroller

Thiscommandisusedtofillarangeofmemorywithasinglevalueoralistofvalues.
Trythefollowingcommandsandcommentonwhattheydo:
F100200A
F2260:2030ff
F100L10A,B

http://helpingtutorial.blogspot.in/2013/01/8086microprocessorprogrammingpart1.html

DigitalLogic
IntroductiontoComputing
8086microprocessorProgramming
(Part8)

2/5

11/08/2016

HelpingTutorial:8086microprocessorProgramming(Part1)
Usedcommandtodisplaythecontentsthatyoujustsaved.Checkiftheymatch.
RegisterCommand
Thiscommandmaybeusedinoneofthreeways:
Displaycontentsofoneregister,allowingittobechanged.
Displayregisters,flags,andthenextinstructionabouttobeexecuted.
Displaytheeightflagsettings,allowinganyorallofthemtobechanged.(Wellnotusethelast
oneinthisexperiment.)
Enter r at the DEBUG prompt and note down what you see on the screen. All the register
contents,theflags,andaninstructionwillbedisplayed.
Nowenterrcx.ThescreenwilldisplaythecontentsofregisterCX,andwillwaitforanewvalue
tobeentered.Enter100andthenverifybyenteringratthenextprompt.
AssembleCommand
Thiscommandassemblesaprogramintomachinelanguage.Letusstartourprogramatlocation
having offset address of 100h. Type a at the DEBUG prompt and press ENTER. The current
address in segment: offset format will be displayed, with the DEBUG asking you to enter
assemblylanguagecommand.Enterthefollowingcommands.PresstheENTERkeyafterevery
line.Thecharactersaftersemicolon()areignoredbyDEBUG.Theyareonlycomments.Forthis
experiment,youdontneedtoincludetheminyourprogram.Ofcoursewhenyoullbewritingbig
programs, it is always recommended to include comments both for clarity and for later
references.
movah,2
mov bh,5
add ah,bh
Int 20h

8086microprocessorProgramming
(Part7)
8086microprocessorProgramming
(Part6)
8086microprocessorProgramming
(Part5)
8086microprocessorProgramming
(Part4)
8086microprocessorProgramming
(Part3)
8086microprocessorProgramming
(Part2)
8086microprocessorProgramming
(Part1)
SevenSegmentDisplaywithParallel
Port
LEDChaserusingParallelPort
UnserstandingParallelPortInterfacing

BloggerGadgets

put02hinthe8bitregisterAH

put05inthe8bitregisterBH

addthetwonumbers,storeresultinAH
endofprogram,returntoDEBUG

Press ENTER key once more to exit from the assemble mode. This is your first assembly
language program. Which adds two numbers together. Now let us see the machine language
code.
Forthiswecanusethedcommandlikethis.
Dcs:100
Thefirstfewbytes(howmanyisnotclearyet)representthemachinelanguagecodeoftheabove
program now well use another DEBUG command that helps us to visualize both the assembly
languagemnemonics(instructions)aswellasthecorrespondingmachinelanguagecode.
UnassembleCommand
Thiscommandtranslatesmemoryintoassemblylanguagemnemonics.Thisprocessiscalleddis
assemblyEnterthefollowingcommandandnotedownwhatyouobserve.
U100
Now you can see both your assembly language program as well as the corresponding machine
code on the screen. Can you now figure out how many bytes are occupied by your small
program? Note down the number. Our next step will be to run this program by executing one
command at a time and then watching the results in various registers. This process is called
singlestepoperationindebuggingofassemblylanguageprograms
TraceCommand
ThiscommandexecutesoneormoreinstructionsfromthecurrentCS:IPlocation(seeAppendix
notes B) or an optional address if specified. The contents of the registers are shown after each
instructionisexecuted.CheckthecontentsofthedataregistersAXandBXusingrcommand.
EnterthefollowingcommandatDEBUGprompt:
t=100
NowcheckthecontentsofAX,andBX.
Againentertandnotethecontents.BothAHandBHwillcontainthebytesyouspecified.
Againentertandnotethecontents.NowAHshouldcontainthesum.Confirmifthisistrue.
Youcanalsoruntheentireprogram,butthenyoullnotbeabletoseetheresultsinthiscase.The
commandisdescribedbelow.
GoCommand
Thiscommandexecutestheprograminmemory.Youcanspecifyastartingaddressandabreak
point, causing the program to stop at a given address. Enter g 100 at eh prompt. The program
startingatlocation100hwillbeexecuted,andyoullseethefollowingmessageatthescreen.
Programterminatednormally.
Nowtryg100102
Inthiscasetheprogramwillstopafterexecutingthefirstinstruction.Thisiswhatiscalledsetting
breakpoints.Youcansetbreakpointsatvariouslocationsinyourmemorytodebuganyerrors.

QUIZ

HereisaninterestingQUIZforyoutotestwhatyoulearn.

http://helpingtutorial.blogspot.in/2013/01/8086microprocessorprogrammingpart1.html

3/5

11/08/2016

HelpingTutorial:8086microprocessorProgramming(Part1)
1. Writeaprogramthataddsthefollowingthreenumberstogether:
0267h+04Ah+19DDh
Debugyourprogramusingthetracecommandandnotedowntheimportantregistercontentsafter
eachstep.
Note:Dontforgettoincludeint20commandtoendyourprogramnormally.
2. Enterthefollowingcommandandexplainandexplainitspurpose.
F200IamastudentofUNIVERSITY
Nowentera100andenterthefollowingprogram,
movcx,20

mov
bx,0200
mov
dl,[bx]
mov
ah,02
inc bx

dec cx

movax,cx

jnz
0106
int 20

initializethecounter
initializetheds:bxtopointtofirstmem.loc.
putinDLthecontentsofDS:BX
callDOSfunction
incrementthemempointer
decrementthecounter
putthecountinaccumulator
jumpbackifcountnotzero
endofprogram

thenusegtoruntheprogram.
DEBUGCommandparameters:
Address: A complete segmentoffset address (see appendix notes B) may be given, or just an
offset.Thesegmentportionmaybeahexadecimalnumberorsegmentregistername.
Examples:

F000:100
Segment,offset

DS:200
Segmentregister,offset
0AF5

Offset
List: Oneormorebytesorstringvalues,separatedbycommas.
Example:

10,20,30,40

A,B,50
Range: A range refers to a span of memory, identified by addresses in one of two formats. In
format1,ifthesecondaddressisomitted,itdefaultstoastandardvalue.Informat2,thevalue
followingtheletterListhenumberofbytestobeprocessedbythecommand.Arangecannotbe
greaterthan10000h(65,536).
Examples:
Format1:address[,address]

100,500
CS:200,300

200
Format2:addressL[value]

100L20

(Refersto20hbytesstartingatlocation100h)
Value:Avalueconsistsofa1to4characterhexadecimalnumber.
Examples:

3A

3A6F

APPENDIXNOTES
FindingtheRealAddress:
Theaddressesinan8086systemareexpressedbycombiningtwohexnumberstogether.Asan
example,youmayfindanaddressexpressedas18F1:0120.Thenumberontheleftiscalledthe
segment address and the one on the right is called the offset address. Both of the hex number
separatedbyacolonare16bitnumbers,however,theaddressbusofthe8086microprocessoris
20bitwide.Togeta20bitrealorabsoluteaddressthesegmentaddressandtheoffsetaddress
are combined together in an unusual way. The segment address (the address on the left) is
shifted left one digit, which is the same as multiplying it by 10h or putting a 0 at its right and
makingita5digit(20bit)hexnumber.Itisthenaddedtotheoffsetaddress(thenumberonthe
right)togettherealorabsoluteaddress.Intheaboveexample,18F1isshiftedleftonepositionto
makeit18F10h.Itisthenaddedto0120htoget19030hwhichistheabsolute20bitaddress.
YoumaybewonderingwhyInteldesignedthe8086familydevicestoaccessmemoryusingthe
segment : offset approach rather than accessing memory directly with 20bit addresses. One of
the reasons for doing so is that the 8086 is a 16bit microprocessor. It performs all its internal
operationsbasedon16bitwords.Thesegment:offsetapproachrequiresonlya16bitnumberto
represent the base address for a segment, and only a 16bit offset to access any location in a
segment.
REFERENCES:
1.DouglasVHall,MicroprocessorsandInterfacing,ProgrammingandHardware,2ndedition.
McGrawHillInternational,1992

http://helpingtutorial.blogspot.in/2013/01/8086microprocessorprogrammingpart1.html

4/5

11/08/2016

HelpingTutorial:8086microprocessorProgramming(Part1)
2.KipR.Irvine,AssemblyLanguagefortheIBMPCMacmillanPublishingCompany,1990
3.RobertLafore,AssemblyLanguagePrimerfortheIBMPC&XT.TheWaiteGroupInc.
1984
4.AvtarSingandWalterA.Trieble,The8086and80286Microprocessor,Hardware,
Software,andInterfacing.PrenticeHallInc.1990

at06:21

Recommend this on Google

Labels:8086microprocessorProgramming

4comments:
kanparaumesh 21August2014at20:11
importantmaterialssoeasy///////////////////////////////////////////////////////////////
Reply

ayushman 11September2014at05:31
goodfindforbesthelp.thanxforsharingsuchaniceinformation..
Reply

Anonymous 4January2016at19:42
Verynice.Thanksformakingsuchnicenotes
Reply

vishalsingh 9February2016at21:55
yeah
Reply

Enteryourcomment...

Commentas:

Publish

Selectprofile...

Preview

NewerPost

Home

OlderPost

Subscribeto:PostComments(Atom)

Simpletemplate.PoweredbyBlogger.

http://helpingtutorial.blogspot.in/2013/01/8086microprocessorprogrammingpart1.html

5/5

You might also like