Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
8086AssemblerTutorialforBeginners(Part1)
8086Assembler
Thistutorialisintendedforthosewhoarenotfamiliarwithassembler
atall,orhaveaverydistantideaaboutit.Ofcourseifyouhave
knowledgeofsomeotherprogramminglanguage(Basic,C/C++,
Pascal...)thatmayhelpyoualot.
Butevenifyouarefamiliarwithassembler,itisstillagoodideato
lookthroughthisdocumentinordertostudyEmu8086syntax.
Itisassumedthatyouhavesomeknowledgeaboutnumber
representation(HEX/BIN),ifnotitishighlyrecommendedtostudy
NumberingSystemsTutorialbeforeyouproceed.
Whatisanassemblylanguage?
Assemblylanguageisalowlevelprogramminglanguage.Youneedto
getsomeknowledgeaboutcomputerstructureinordertounderstand
anything.ThesimplecomputermodelasIseeit:
Thesystembus(showninyellow)connectsthevariouscomponents
ofacomputer.
TheCPUistheheartofthecomputer,mostofcomputationsoccur
insidetheCPU.
RAMisaplacetowheretheprogramsareloadedinordertobe
executed.
InsidetheCPU
http://ce.kashanu.ac.ir/sabaghian/assembly/8086%20tutorial/8086%20Assembler%20Tutorial%20for%20Beginners%20(Part%201).htm
1/3
10/2/2016
8086AssemblerTutorialforBeginners(Part1)
GENERALPURPOSEREGISTERS
8086CPUhas8generalpurposeregisters,eachregisterhasitsown
name:
AXtheaccumulatorregister(dividedintoAH/AL).
BXthebaseaddressregister(dividedintoBH/BL).
CXthecountregister(dividedintoCH/CL).
DXthedataregister(dividedintoDH/DL).
SIsourceindexregister.
DIdestinationindexregister.
BPbasepointer.
SPstackpointer.
Despitethenameofaregister,it'stheprogrammerwhodetermines
theusageforeachgeneralpurposeregister.Themainpurposeofa
registeristokeepanumber(variable).Thesizeoftheaboveregisters
is16bit,it'ssomethinglike:0011000000111001b(inbinaryform),
or12345indecimal(human)form.
4generalpurposeregisters(AX,BX,CX,DX)aremadeoftwo
separate8bitregisters,forexampleifAX=0011000000111001b,
thenAH=00110000bandAL=00111001b.Therefore,whenyou
modifyanyofthe8bitregisters16bitregisterisalsoupdated,and
viceversa.Thesameisforother3registers,"H"isforhighand"L"is
forlowpart.
BecauseregistersarelocatedinsidetheCPU,theyaremuchfaster
thanmemory.Accessingamemorylocationrequirestheuseofa
systembus,soittakesmuchlonger.Accessingdatainaregister
usuallytakesnotime.Therefore,youshouldtrytokeepvariablesin
theregisters.Registersetsareverysmallandmostregistershave
specialpurposeswhichlimittheiruseasvariables,buttheyarestill
anexcellentplacetostoretemporarydataofcalculations.
http://ce.kashanu.ac.ir/sabaghian/assembly/8086%20tutorial/8086%20Assembler%20Tutorial%20for%20Beginners%20(Part%201).htm
2/3
10/2/2016
8086AssemblerTutorialforBeginners(Part1)
SEGMENTREGISTERS
CSpointsatthesegmentcontainingthecurrentprogram.
DSgenerallypointsatsegmentwherevariablesaredefined.
ESextrasegmentregister,it'suptoacodertodefineitsusage.
SSpointsatthesegmentcontainingthestack.
Althoughitispossibletostoreanydatainthesegmentregisters,this
isneveragoodidea.Thesegmentregistershaveaveryspecial
purposepointingataccessibleblocksofmemory.
Segmentregistersworktogetherwithgeneralpurposeregisterto
accessanymemoryvalue.Forexampleifwewouldliketoaccess
memoryatthephysicaladdress12345h(hexadecimal),weshould
settheDS=1230handSI=0045h.Thisisgood,sincethiswaywe
canaccessmuchmorememorythanwithasingleregisterthatis
limitedto16bitvalues.
CPUmakesacalculationofphysicaladdressbymultiplyingthe
segmentregisterby10handaddinggeneralpurposeregistertoit
(1230h*10h+45h=12345h):
Theaddressformedwith2registersiscalledaneffectiveaddress.
BydefaultBX,SIandDIregistersworkwithDSsegmentregister
BPandSPworkwithSSsegmentregister.
Othergeneralpurposeregisterscannotformaneffectiveaddress!
Also,althoughBXcanformaneffectiveaddress,BHandBLcannot!
SPECIALPURPOSEREGISTERS
IPtheinstructionpointer.
FlagsRegisterdeterminesthecurrentstateoftheprocessor.
IPregisteralwaysworkstogetherwithCSsegmentregisterandit
pointstocurrentlyexecutinginstruction.
FlagsRegisterismodifiedautomaticallybyCPUaftermathematical
operations,thisallowstodeterminethetypeoftheresult,andto
determineconditionstotransfercontroltootherpartsoftheprogram.
Generallyyoucannotaccesstheseregistersdirectly.
>>>NextPart>>>
http://ce.kashanu.ac.ir/sabaghian/assembly/8086%20tutorial/8086%20Assembler%20Tutorial%20for%20Beginners%20(Part%201).htm
3/3