Você está na página 1de 3

4/17/2016

ABOUT ASSEMBLERS: ASSEMBLER ALGORITHM AND DATA STRUCTURES

More NextBlog

CreateBlog SignIn

ABOUT ASSEMBLERS

THURSDAY, SEPTEMBER 25, 2008

ASSEMBLER ALGORITHM AND DATA


STRUCTURES
Oursimpleassemblerusestwomajorinternaldata

BLOG ARCHIVE

structuretheOperationCodetable(OPTAB)andtheSymbol

2008 (4)

Table(SYMTAB).OPTABisusedtolookupmnemonic
operationcodesandtranslatethemtotheirmachine
languageequivalents.SYMTABisusedtostore
values(addresses)assignedtolabels.

September (4)
ASSEMBLER ALGORITHM
AND DATA STRUCTURES
FUNCTIONS :

WealsoneedaLocationcounterLOCCTR.Thisisavariable

Directives:

thatisusedtohelpintheassignmentofaddresses.LOCCTR

Assemblers :Indroduction

isinitializedtothebeginningaddressspecifiedintheSTART
statement.Aftereachsourcestatementisprocessed,the
lengthoftheassembledinstructionsordateareatobe
generatedisaddedtoLOCCTR.Thuswheneverwereacha
labelinthesourceprogram,thecurrentvalueofLOCCTR
givestheaddresstobeassociatedwiththatlabel.

ABOUT ME
B RIS K I
VI EW M Y C OMP LET E P R OFI LE

TheOperationcodeTablemustcontainthemnemonic
operationcodeanditsmachinelanguageequivalent.Inmore
complexassembles,thistablealsocontainsinformation
aboutinstructionformatandlength.DuringPass1,OPTABis
usedtolookupandvalidateopearationcodedinthesource
program.Inpass2,itisusedtotranslatetheoperation
codestomachinelanguage.Actually,inoursimpleSIC
assembler,bothoftheseprocessescouldbedonetogetherin

ABOUT ASSEMBLERS

ASSEMBLER ALGORITHM AND


DATA STRUCTURES
FUNCTIONS :
Directives:
Assemblers :Indroduction

eitherPASS1orPASS2.However,foramachinethathas
instructionsofdifferentlengths,wemustsearchOPTABin
thefirstpasstofindtheinstructionslengthforincrementing
LOCCTR.Likewise,wemusthavetheinformationfrom
OPTABisPASS2totelluswhichinstructionformattousein
assemblingtheinstruction,andmypeculiaritiesoftheobject
codeinstruction.Wehavechosentoretainthisstructurein
http://briskiassemblers.blogspot.ca/2008/09/assembler-algorithm-and-data-structures.html

1/3

4/17/2016

ABOUT ASSEMBLERS: ASSEMBLER ALGORITHM AND DATA STRUCTURES

thecurrentdiscussionbecauseitistypicalofmostreal
assembles.
OPTABisusuallyorganizedasahashtable,withmnemonic
operationcodeasthekey.Thehashtableorganizationis
particularlyappropriate,sinceitprovidesfastretrievalwith
aminimumofsearching.Inmostcases,OPTABisastatic
tablethatis,entriesarenotnormallyaddedtoordeleted
fromit.Insuchcasesitispossibletodesignaspecialhashing
functionorotherdatastructuretogiveoptimum
performancefortheparticularsetofkeysbeingstored.Most
ofthetime,however,ageneralpurposehashingmethodis
used.
TheSymboltable(SYMTAB)includesthenameandvalue
(address)foreachlabelinthesourceprogram,togetherwith
flagstoindicateerrorconditions(e.g,.asymboldefinedin
twodifferentplaces).Thistablemayalsocontainother
informationaboutthedataareaorinstructionlabeledfor
example,itstypeorlength.DuringPass1oftheassembler,
labelsareenteredintoSYMTABastheyareencounterdinthe
sourceprogram,alongwiththeirassignedaddresses(form
LOCCTR).DuringPass2,symbolsusedasoperandsare
lookedupinSYMTABtoobtaintheaddressestobeinserted
intheassembledintructions.
SYMTABisusuallyorganizedasahashtableforefficiencyor
insertionandretrieval.Sinceentriesarerarelydeletedfrom
thistable,efficiencyofdeletionisnotanimportant
consideration.BecauseSYMTABisusedhavilythroughout
theassemble,careshouldbetakenintheselectionofa
hashingfunction.Programmersoftenselectmanylabelsthat
havesimilarcharacteristicsforexample,labelsthatstart
orendwiththesamecharacters(likeLOOP1,LOOP2)orare
ofthesamelength.Itisimportantthatthehashingfuction
usedperformwellwithsuchnorandomkeys.Divisionofthe
entirekeybyaprimetablelengthoftengivesgoodresult.
Itispossibletobothpassesoftheassemblertoreadthe
originalsourceprogramasinput.However,thereiscertain
information(suchaslocationcountervaluesanderrorflags
forstatements)thatcanorshouldbecommunicatedbetween
thetwopasses.Forthisreason,Passusuallywritesan
INTERMEDIATEFILEthatcontainseachsourcestatement
togetherwithitsassignedaddress,errorindicators,etc,.
ThisfileisusedastheinputtoPass2.Thisworkingcopyof
http://briskiassemblers.blogspot.ca/2008/09/assembler-algorithm-and-data-structures.html

2/3

4/17/2016

ABOUT ASSEMBLERS: ASSEMBLER ALGORITHM AND DATA STRUCTURES

thesourceprogramcanalsobeusedtoretaintheresultsof
certainoperationsthatmaybeperformedduringPass1,so
theseneednotbeperformedagainduringPass2.Similarly,
pointersintoOPTABandSYMTABmayretainedforeach
operationcodeandsymbolused.Thisavoidstheneedto
repeatmanyofthetablesearchingoperations.Weassume
forsimplicitythatthesourcelinesarewritteninafixed
formatwithfieldsLABEL,OPCODE,andOPERAND.Ifone
ofthesefieldscontainsacharactedstringthatrepresentsa
number,wedenoteitsnumericvaluewiththepreficx#(for
example,#[OPERAND]).
POST ED BY BR I SKI AT 9: 0 4 AM

1COMMENT:
Shanthakumar V said...
useful :)
JULY 20, 201 4 AT 5: 1 5 PM
Post a Comment
Home

Older Post

Subscribe to: Post Comments (Atom)

http://briskiassemblers.blogspot.ca/2008/09/assembler-algorithm-and-data-structures.html

3/3

Você também pode gostar