BerkeleyVAX/UNIXAssemblerReferenceManual 1 BerkeleyVAX/UNIXAssemblerReferenceManual JohnF.Reiser BellLaboratories, Holmdel,NJ and RobertR.Henry1 ElectronicsResearchLaboratory UniversityofCalifornia Berkeley,CA94720 November5,1979 Revised February9,1983 1.Introduction ThisdocumentdescribestheusageandinputsyntaxoftheUNIXVAX-11assembleras.As isdesignedforassemblingthecodeproducedbythe‘‘C’’compiler;certainconcessionshavebeen madetohandlecodewrittendirectlybypeople,butingenerallittlesympathyhasbeen extended.Thisdocumentisintendedonlyforthewriterofacompileroramaintainerofthe assembler. 1.1.AssemblerRevisionssinceNovember5,1979 Therehasbeenonemajorchangetoassincethelastrelease.Ashasbeenupdatedto assemblethenewinstructionsanddataformatsfor“G”and“H”floatingpointnumbers,as wellasthenewqueueinstructions. 1.2.FeaturesSupported,butNoLongerEncouragedasofFebruary9,1983 Thesefeature(s)inasaresupported,butnolongerencouraged. -Thecolonoperatorforfieldinitializationislikelytodisappear. 2.Usage Asisinvokedwiththesecommandarguments: as[−LVWJR][−d.cp0][−DTS][−tdirectory][−ooutput][name1]...[namen] The−Lflaginstructstheassemblertosavelabelsbeginningwitha“L”inthesymbol tableportionoftheoutputfile.Labelsarenotsavedbydefault,asthedefaultactionofthelink editorldistodiscardthemanyway. The−Vflagtellstheassemblertoplaceitsinterpasstemporaryfileintovirtualmemory. Innormalcircumstances,thesystemmanagerwilldecidewherethetemporaryfileshouldlie. Ourexperimentswithverylargetemporaryfilesshowthatplacingthetemporaryfileintovirtual memorywillsaveabout13%oftheassemblytime,wherethesizeofthetemporaryfileisabout 350Kbytes.Mostassemblersourceswillnotbethislong. 1PreparationofthispapersupportedinpartbytheNationalScienceFoundationundergrantMCS#78-07291. February9,1983 1 2 BerkeleyVAX/UNIXAssemblerReferenceManual The−Wturnsofallwarningerrorreporting. The−JflagforcesUNIXstylepseudo−branchinstructionswithdestinationsfurtheraway thanabytedisplacementtobeturnedintojumpinstructionswith4byteoffsets.The−Jflag buysyounothingif−d2isset.(See§8.4,andfutureworkdescribedin§11) The−Rflageffectivelyturns“.datan”directivesinto“.textn”directives.Thisobviates theneedtoruneditorscriptsonassemblersourceto“read−only”fixinitializeddatasegments. Uninitializeddata(via.lcommand.commdirectives)isstillassembledintothedataorbss segments. The−dflagspecifiesthenumberofbyteswhichtheassemblershouldallowforadisplacementwhenthevalueofthedisplacementexpressionisundefinedinthefirstpass.Thepossible valuesofnare1,2,or4;theassembleruses4bytesif-disnotspecified.See§8.2. Providedthe−Vflagisnotset,the−tflagcausestheassemblertoplaceitssingletemporaryfileinthedirectoryinsteadofin/tmp. The−oflagcausestheoutputtobeplacedonthefileoutput.Bydefault,theoutputof theassemblerisplacedinthefilea.outinthecurrentdirectory. Theinputtotheassemblerisnormallytakenfromthestandardinput.Iffilearguments occur,thentheinputistakensequentiallyfromthefilesname1,name2...namenThisisnotto saythatthefilesareassembledseparately;name1iseffectivelyconcatenatedtoname2,somultipledefinitionscannotoccuramongsttheinputsources. The−D(debug),−T(tokentrace),andthe−S(symboltable)flagsenableassembler traceinformation,providedthattheassemblerhasbeencompiledwiththedebuggingcode enabled.Theinformationprintedislongandboring,butusefulwhendebuggingtheassembler. 3.Lexicalconventions Assemblertokensincludeidentifiers(alternatively,“symbols”or“names”),constants,and operators. 3.1.Identifiers Anidentifierconsistsofasequenceofalphanumericcharacters(includingperiod“.”, underscore“−”,anddollar“$”).Thefirstcharactermaynotbenumeric.Identifiersmaybe (practically)arbitrarylong;allcharactersaresignificant. 3.2.Constants 3.2.1.Scalarconstants Allscalar(nonfloatingpoint)constantsare(potentially)128bitswide.Suchconstants areinterpretedastwo’scomplementnumbers.Notethat64bit(quadwords)and128bit (octalword)integersareonlypartiallysupportedbytheVAXhardware.Inaddition,128bit integersareonlysupportedbytheextendedVAXarchitecture.Assupports64and128bit integersonlysotheycanbeusedasimmediateconstantsortofillinitializeddataspace.As cannotperformarithmeticonconstantslargerthan32bits. Scalarconstantsareinitiallyevaluatedtoafull128bits,butarepareddownbydiscardinghighordercopiesofthesignbitandcategorizingthenumberasalong,quadoroctalinteger.Numberswithlessprecisionthan32bitsaretreatedas32bitquantities. Thedigitsare“0123456789abcdefABCDEF”withtheobviousvalues. Anoctalconstantconsistsofasequenceofdigitswithaleadingzero. Adecimalconstantconsistsofasequenceofdigitswithoutaleadingzero. 2 February9,1983 BerkeleyVAX/UNIXAssemblerReferenceManual 3 Ahexadecimalconstantconsistsofthecharacters“0x”(or“0X”)followedbyasequence ofdigits. Asingle-characterconstantconsistsofasinglequote“′”followedbyanASCIIcharacter, includingASCIInewline.Theconstant’svalueisthecodeforthegivencharacter. 3.2.2.FloatingPointConstants FloatingpointconstantsareinternallyrepresentedintheVAXfloatingpointformatthat isspecifiedbythelexicalformoftheconstant.Usingthemetanotationthat[dec]isadecimal digit(“0123456789”),[expt]isatypespecificationcharacter(“fFdDhHgG”),[expe]isaexponentdelimiterandtypespecificationcharacter(“eEfFdDhHgG”),x*means0ormore occurencesofx,x+means1ormoreoccurencesofx,thenthegenerallexicalformofafloatingpointnumberis: 0[expe]([+-])[dec]+(.)([dec]*)([expt]([+-])(dec]+)) Thestandardsemanticinterpretationisusedforthesignedinteger,fractionandsignedpower of10exponent.Iftheexponentdelimiterisspecified,itmustbeeitheran“e”or“E”,ormust agreewiththeinitialtypespecificationcharacterthatisused.Thetypespecificationcharacterspecifiesthetypeandrepresentationoftheconstructednumber,asfollows: Notethat“G”and“H”formatfloatingpointnumbersarenotsupportedbyallimplementationsoftheVAXarchitecture.Asdoesnotrequiretheaugmentedarchitectureinordertorun. Theassemblerusesthelibraryroutineatof()toconvert“F”and“D”numbers,anduses itsownconversionroutine(derivedfromatof,andbelievedtobenumericallyaccurate)toconvert“G”and“H”floatingpointnumbers. Collectively,allfloatingpointnumbers,togetherwithquadandoctalscalarsarecalled Bignums.WhenasrequiresaBignum,a32bitscalarquantitymayalsobeused. 3.2.3.StringConstants Astringconstantisdefinedusingthesamesyntaxandsemanticsasthe‘‘C’’language uses.Stringsbeginandendwitha“’’”(doublequote).TheDECMACRO-32assemblerconven-tionsforflexiblestringquotingisnotimplemented.All‘‘C’’backslashconventionsare observed;thebackslashconventionspeculiartothePDP-11assemblerarenotobserved.Strings areknownbytheirvalueandtheirlength;theassemblerdoesnotimplicitlyendstringswitha nullbyte. 3.3.Operators Thereareseveralsingle-characteroperators;see§6.1. 3.4.Blanks Blankandtabcharactersmaybeinterspersedfreelybetweentokens,butmaynotbeused withintokens(exceptcharacterconstants).Ablankortabisrequiredtoseparateadjacent identifiersorconstantsnototherwiseseparated. 3.5.ScratchMarkComments Thecharacter“#”introducesacomment,whichextendsthroughtheendofthelineon whichitappears.Commentsstartingincolumn1,havingtheformat“#expressionstring”, areinterpretedasanindicationthattheassemblerisnowassemblingfilestringatlineexpression.Thus,onecanusethe‘‘C’’preprocessoronanassemblylanguagesourcefile,andusethe #includeand#definepreprocessordirectives.(Notethattheremaynotbeanassembler February9,1983 3 4 BerkeleyVAX/UNIXAssemblerReferenceManual commentstartingincolumn1iftheassemblersourceisgiventothe‘‘C’’preprocessor,asitwill beinterpretedbythepreprocessorinawaynotintended.)Commentsareotherwiseignoredby theassembler. 3.6.‘‘C’’StyleComments Theassemblerwillrecognize‘‘C’’stylecomments,introducedwiththeprologue/*and endingwiththeepilogue*/.‘‘C’’stylecommentsmayextendacrossmultiplelines,andarethe preferredcommentstyletouseifonechoosestousethe‘‘C’’preprocessor. 4.SegmentsandLocationCounters Assembledcodeanddatafallintothreesegments:thetextsegment,thedatasegment,and thebsssegment.TheUNIXoperatingsystemmakessomeassumptionsaboutthecontentofthese segments;theassemblerdoesnot.Withinthetextanddatasegmentsthereareanumberofsubsegments,distinguishedbynumber(“text0”,“text1”,...“data0”,“data1”,...).Currently therearefoursubsegmentseachintextanddata.Thesubsegmentsareforprogrammingconvenienceonly. Beforewritingtheoutputfile,theassemblerzero-padseachtextsubsegmenttoamultiple offourbytesandthenconcatenatesthesubsegmentsinordertoformthetextsegment;ananalogousoperationisdoneforthedatasegment.Requestingthattheloaderdefinesymbolsand storageregionsistheonlyactionallowedbytheassemblerwithrespecttothebsssegment. Assemblybeginsin“text0”. Associatedwitheach(sub)segmentisanimplicitlocationcounterwhichbeginsatzeroand isincrementedby1foreachbyteassembledintothe(sub)segment.Thereisnowaytoexplicitly referencealocationcounter.Notethatthelocationcountersofsubsegmentsotherthan“text0” and“data0”behavepeculiarlyduetotheconcatenationusedtoformthetextanddatasegments. 5.Statements Asourceprogramiscomposedofasequenceofstatements.Statementsareseparated eitherbynew-linesorbysemicolons.Therearetwokindsofstatements:nullstatementsand keywordstatements.Eitherkindofstatementmaybeprecededbyoneormorelabels. 5.1.NamedGlobalLabels Agloballabelconsistsofanamefollowedbyacolon.Theeffectofanamelabelisto assignthecurrentvalueandtypeofthelocationcountertothename.Anerrorisindicatedin pass1ifthenameisalreadydefined;anerrorisindicatedinpass2ifthevalueassigned changesthedefinitionofthelabel. Agloballabelisreferencedbyitsname. Globallabelsbeginningwitha“L”arediscardedunlessthe−Loptionisineffect. 5.2.NumericLocalLabels Anumericlabelconsistsofadigit0to9followedbyacolon.Suchalabelservesto definetemporarysymbolsoftheform“nb”and“nf”,wherenisthedigitofthelabel.Asin thecaseofnamelabels,anumericlabelassignsthecurrentvalueandtypeofthelocation countertothetemporarysymbol.However,severalnumericlabelswiththesamedigitmaybe usedwithinthesameassembly.Referencestosymbolsoftheform“nb”refertothefirst numericlabel“n:”backwardsfromthereference;“nf”symbolsrefertothefirstnumericlabel “n:”forwardsfromthereference.Suchnumericlabelsconservetheinventivepowersofthe humanprogrammer. 4 February9,1983 BerkeleyVAX/UNIXAssemblerReferenceManual 5 Forvariousreasons,asturnslocallabelsintolabelsoftheformLn.$m.Although unlikely,thesegeneratedlabelsmayconflictwithprogrammerdefinedlabels. 5.3.Nullstatements Anullstatementisanemptystatementignoredbytheassembler.Anullstatementmay belabeled,however. 5.4.Keywordstatements Akeywordstatementbeginswithoneofthemanypredefinedkeywordsknowntoas;the syntaxoftheremainderofthestatementdependsonthekeyword.Allinstructionopcodesare keywords.Theremainingkeywordsareassemblerpseudo-operations,alsocalleddirectives.The pseudo-operationsarelistedin§8,togetherwiththesyntaxtheyrequire. 6.Expressions Anexpressionisasequenceofsymbolsrepresentingavalue.Itsconstituentsareidentifiers,constants,operators,andparentheses.Eachexpressionhasatype. Alloperatorsinexpressionsarefundamentallybinaryinnature.Arithmeticistwo’scomplementandhas32bitsofprecision.Ascannotdoarithmeticonfloatingpointnumbers,quad oroctalprecisionscalarnumbers.Therearefourlevelsofprecedence,listedherefromlowest precedenceleveltohighest: Alloperatorsofthesameprecedenceareevaluatedstrictlylefttoright,exceptfortheevaluationorderenforcedbyparenthesis. 6.1.ExpressionOperators Theoperatorsare: Expressionsmaybegroupedbyuseofparentheses,“(”and“)”. 6.2.DataTypes Theassemblermanipulatesseveraldifferenttypesofexpressions.Thetypeslikelytobe metexplicitlyare: undefinedUponfirstencounter,eachsymbolisundefined.Itmaybecomeundefinedifitis assignedanundefinedexpression.Itisanerrortoattempttoassembleanundefined expressioninpass2;inpass1,itisnot(exceptthatcertainkeywordsrequire operandswhicharenotundefined). undefinedexternal Asymbolwhichisdeclared.globlbutnotdefinedinthecurrentassemblyisan undefinedexternal.Ifsuchasymbolisdeclared,thelinkeditorldmustbeusedto loadtheassembler’soutputwithanotherroutinethatdefinestheundefinedreference. absoluteAnabsolutesymbolisdefinedultimatelyfromaconstant.Itsvalueisunaffectedby anypossiblefutureapplicationsofthelink-editortotheoutputfile. textThevalueofatextsymbolismeasuredwithrespecttothebeginningofthetextsegmentoftheprogram.Iftheassembleroutputislink-edited,itstextsymbolsmay changeinvaluesincetheprogramneednotbethefirstinthelinkeditor’soutput. Mosttextsymbolsaredefinedbyappearingaslabels.Atthestartofanassembly, February9,1983 5 6 BerkeleyVAX/UNIXAssemblerReferenceManual thevalueof“.”is“text0”. dataThevalueofadatasymbolismeasuredwithrespecttotheoriginofthedatasegmentofaprogram.Liketextsymbols,thevalueofadatasymbolmaychangeduringasubsequentlink-editorrunsincepreviouslyloadedprogramsmayhavedata segments.Afterthefirst.datastatement,thevalueof“.”is“data0”. bssThevalueofabsssymbolismeasuredfromthebeginningofthebsssegmentofa program.Liketextanddatasymbols,thevalueofabsssymbolmaychangeduring asubsequentlink-editorrun,sincepreviouslyloadedprogramsmayhavebssseg-ments. externalabsolute,text,data,orbss Symbolsdeclared.globlbutdefinedwithinanassemblyasabsolute,text,data,or bsssymbolsmaybeusedexactlyasiftheywerenotdeclared.globl;however,their valueandtypeareavailabletothelinkeditorsothattheprogrammaybeloaded withothersthatreferencethesesymbols. registerThesymbols r0r1r2r3r4r5r6r7r8r9r10r11r12r13r14r15apfpsppc arepredefinedasregistersymbols.Inaddition,the“%”operatorconvertsthefollowingabsoluteexpressionwhosevalueisbetween0and15intoaregisterreference. othertypes Eachkeywordknowntotheassemblerhasatypewhichisusedtoselecttheroutine whichprocessestheassociatedkeywordstatement.Thebehaviorofsuchsymbols whennotusedaskeywordsisthesameasiftheywereabsolute. 6.3.TypePropagationinExpressions Whenoperandsarecombinedbyexpressionoperators,theresulthasatypewhich dependsonthetypesoftheoperandsandontheoperator.Therulesinvolvedarecomplexto statebutwereintendedtobesensibleandpredictable.Forpurposesofexpressionevaluation theimportanttypesare Thecombinationrulesarethen (1)Ifoneoftheoperandsisundefined,theresultisundefined. (2)Ifbothoperandsareabsolute,theresultisabsolute. (3)Ifanabsoluteiscombinedwithoneofthe“othertypes”mentionedabove,theresulthas theothertype.An“othertype”combinedwithanexplicitlydiscussedtypeotherthan absoluteitactslikeanabsolute. Furtherrulesapplyingtoparticularoperatorsare: +Ifoneoperandistext-,data-,orbss-segmentrelocatable,orisanundefinedexternal,the resulthasthepostulatedtypeandtheotheroperandmustbeabsolute. Ifthefirstoperandisarelocatabletext-,data-,orbss-segmentsymbol,thesecond operandmaybeabsolute(inwhichcasetheresulthasthetypeofthefirstoperand);or thesecondoperandmayhavethesametypeasthefirst(inwhichcasetheresultisabsolute).Ifthefirstoperandisexternalundefined,thesecondmustbeabsolute.Allother combinationsareillegal. 6 February9,1983 BerkeleyVAX/UNIXAssemblerReferenceManual 7 others Itisillegaltoapplytheseoperatorstoanybutabsolutesymbols. 7.Pseudo-operations(Directives) Thekeywordslistedbelowintroducedirectivesorinstructions,andinfluencethelater behavioroftheassemblerforthisstatement.Themetanotation [stuff] meansthat0ormoreinstancesofthegiven“stuff”mayappear. Boldfacetokensmustappearliterally;wordsinitalicwordsaresubstitutable. Thepseudo−operationslistedbelowaregroupedintofunctionalcategories. 7.1.InterfacetoaPreviousPass Assoonastheassemblerseesthisdirective,itignoresallfurtherinput(butitdoesread totheendoffile),andabortstheassembly.Nofilesarecreated.Itisanticipatedthatthis wouldbeusedinapipeinterconnectedversionofacompiler,wherethefirstmajorsyntaxerror wouldcausethecompilertoissuethisdirective,savingunnecessaryworkinassemblingcode thatwouldhavetobediscardedanyway. Thisdirectivecausestheassemblertothinkitisinfilestring,soerrormessagesreflectthe propersourcefile. Thisdirectivecausestheassemblertothinkitisonlineexpressionsoerrormessages reflectthepropersourcefile. Theonlyeffectofassemblingmultiplefilesspecifiedinthecommandstringistoinsertthe fileandlinedirectives,withtheappropriatevalues,atthebeginningofthesourcefromeach file. Thisistheonlyinstancewhereacommentismeaningfultotheassembler.The“#”must beinthefirstcolumn.Thismetacommentcausestheassemblertobelieveitisonlineexpression.Thesecondargument,ifincluded,causestheassemblertobelieveitisinfilestring,otherwisethecurrentfilenamedoesnotchange. 7.2.LocationCounterControl Thesetwopseudo-operationscausetheassemblertobeginassemblingintotheindicated textordatasubsegment.Ifspecified,theexpressionmustbedefinedandabsolute;anomitted expressionistreatedaszero.Theeffectofa.datadirectiveistreatedasa.textdirectiveifthe −Rassemblyflagisset.Assemblystartsinthe.text0subsegment. Thedirectives.alignand.orgalsocontroltheplacementofthelocationcounter. 7.3.FilledData Thelocationcounterisadjustedsothattheexpressionlowestbitsofthelocationcounter becomezero.Thisisdonebyassemblingfrom0to2align−exprbytes,takenfromtheloworder byteoffill−expr.Ifpresent,fill−exprmustbeabsolute;otherwiseitdefaultsto0.Thus February9,1983 7 8 BerkeleyVAX/UNIXAssemblerReferenceManual “.align2”padsbynullbytestomakethelocationcounterevenlydivisibleby4.Thealignexpr mustbedefined,absolute,nonnegative,andlessthan16. Warning:thesubsegmentconcatenationconventionandthecurrentloaderconventions maynotpreserveattemptsataligningtomorethan2low-orderzerobits. Thelocationcounterissetequaltothevalueoforg−expr,whichmustbedefinedand absolute.Thevalueoftheorg−exprmustbegreaterthanthecurrentvalueofthelocation counter.Spacebetweenthecurrentvalueofthelocationcounterandthedesiredvalueare filledwithbytestakenfromtheloworderbyteoffill−expr,whichmustbeabsoluteand defaultsto0. Thelocationcounterisadvancedbyspace−exprbytes.Space−exprmustbedefinedand absolute.Thespaceisfilledinwithbytestakenfromtheloworderbyteoffill−expr,which mustbedefinedandabsolute.Fill−exprdefaultsto0.The.filldirectiveisamoregeneralway toaccomplishthe.spacedirective. Allthreeexpressionsmustbeabsolute.fill−expr,treatedasanexpressionofsize size−exprbytes,isassembledandreplicatedrep−exprtimes.Theeffectistoadvancethecurrentlocationcounterrep−expr∗size−exprbytes.size−exprmustbebetween1and8. 7.4.SymbolDefinitions 7.5.InitializedData Theexpressionsinthecomma-separatedlistaretruncatedtothesizeindicatedbythekey word: andassembledinsuccessivelocations.Theexpressionsmustbeabsolute. Eachexpressionmayoptionallybeoftheform: Inthiscase,thevalueofexpression2istruncatedtoexpression1bits,andassembledinthenext expression1bitfieldwhichfitsinthenaturaldatasizebeingassembled.Bitswhichareskipped becauseafielddoesnotfitarefilledwithzeros.Thus,“.byte123”isequivalentto“.byte 8:123”,and“.byte3:1,2:1,5:1”assemblestwobytes,containingthevalues9and1. NB:Bitfieldinitializationwiththecolonoperatorislikelytodisappearinfuturereleases oftheassembler. TheseinitializeBignums(see§3.2.2)insuccessivelocationswhosesizeisafunctiononthe keyword.ThetypeoftheBignums(determinedbytheexponentfield,orlackthereof)may notagreewithtypeimpliedbythekeyword.Thefollowingtableshowsthekeywords,their size,andthedatatypesfortheBignumstheyexpect. Aswillcorrectlyperformotherfloatingpointconversionswhileinitializing,butissuesa warningmessage.Asperformsallfloatingpointinitializationsandconversionsusingonlythe facilitiesdefinedintheoriginal(native)architecture. 8 February9,1983 BerkeleyVAX/UNIXAssemblerReferenceManual 9 Eachstringinthelistisassembledintosuccessivelocations,withthefirstletterinthe stringbeingplacedintothefirstlocation,etc.The.asciidirectivewillnotnullpadthestring; the.ascizdirectivewillnullpadthestring.(Recallthatstringsareknownbytheirlength,and neednotbeterminatedwithanull,andthatthe‘‘C’’conventionsforescapingareunderstood.) The.asciidirectiveisidenticalto: .bytestring0,string1,... Providedthenameisnotdefinedelsewhere,itstypeismade“undefinedexternal”,andits valueisexpression.Infactthenamebehavesinthecurrentassemblyjustlikeanundefined external.However,thelinkeditorldhasbeenspecial-casedsothatallexternalsymbolswhich arenototherwisedefined,andwhichhaveanon-zerovalue,aredefinedtolieinthebssseg-ment,andenoughspaceisleftafterthesymboltoholdexpressionbytes. expressionbyteswillbeallocatedinthebsssegmentandnameassignedthelocationof thefirstbyte,butthenameisnotdeclaredasglobalandhencewillbeunknowntothelinkeditor. Thisstatementmakesthenameexternal.Ifitisotherwisedefined(by.setorbyappearanceasalabel)itactswithintheassemblyexactlyasifthe.globlstatementwerenotgiven; however,thelinkeditormaybeusedtocombinethisobjectmodulewithothermodulesreferringtothissymbol. Conversely,ifthegivensymbolisnotdefinedwithinthecurrentassembly,thelinkeditor cancombinetheoutputofthisassemblywiththatofotherswhichdefinethesymbol.The assemblermakesallotherwiseundefinedsymbolsexternal. The(name,expression)pairisenteredintothesymboltable.Multiple.setstatements withthesamenamearelegal;themostrecentvaluereplacesallpreviousvalues. Auniqueandotherwiseunreferencableinstanceofthe(name,expression)pairiscreated inthesymboltable.TheFortran77compilerusesthismechanismtopasslocalsymboldefinitionstothelinkeditoranddebugger. Thestabdirectivesplacesymbolsinthesymboltableforthesymbolicdebugger,sdb2.A “stab”isasymboltableentry.The.stabsisastringstab,the.stabnisastabnothavinga string,andthe.stabdisa“dot”stabthatimplicitlyreferences“dot”,thecurrentlocation counter. Thestringinthe.stabsdirectiveisthenameofasymbol.Ifthesymbolnameiszero, the.stabndirectivemaybeusedinstead. Theotherexpressionsarestoredinthenameliststructureofthesymboltableandpreservedbytheloaderforreferencebysdb;thevalueoftheexpressionsarepeculiartoformats requiredbysdb. 2Katseff,H.P.Sdb:ASymbolDebugger.BellLaboratories,Holmdel,NJ.April12,1979. Katseff,H.P.SymbolTableFormatforSdb,File39394,BellLaboratories,Holmdel,NJ.March14,1979. February9,1983 9 10 BerkeleyVAX/UNIXAssemblerReferenceManual isusedasasymboltabletag(nlistfieldn−type). seemstoalwaysbezero(nlistfieldn−other). isusedforeitherthesourcelinenumber,orforanestinglevel(nlistfieldn−desc). isusedastagspecificinformation(nlistfieldn−value).Inthecaseofthe.stabddirective,this expressionisnonexistent,andistakentobethevalueofthelocationcounteratthefollowing instruction.Sincethereisnoassociatednamefora.stabddirective,itcanonlybeusedincircumstanceswherethenameiszero.Theeffectofa.stabddirectivecanbeachievedbyoneof theother.stabxdirectivesinthefollowingmanner: .stabnexpr1,expr2,expr3,LLn LLn: The.stabddirectiveispreferred,becauseitdoesnotclogthesymboltablewithlabels usedonlyforthestabsymbolentries. 8.Machineinstructions Thesyntaxofmachineinstructionstatementsacceptedbyasisgenerallysimilartothe syntaxofDECMACRO-32.Therearedifferences,however. 8.1.Characterset Asusesthecharacter“$”insteadof“#”forimmediateconstants,andthecharacter“*” insteadof“@”forindirection.Opcodesandregisternamesarespelledwithlower-caserather thanupper-caseletters. 8.2.SpecifyingDisplacementLengths Undercertaincircumstances,thefollowingconstructsare(optionally)recognizedbyasto indicatethenumberofbytestoallocateforthedisplacementusedwhenconstructingdisplacementanddisplacementdeferredaddressingmodes: Onecanalsouselowercaseb,worlinsteadoftheuppercaseletters.Theremustbeno spacebetweenthesizespecifierletterandthe“ˆ ”or“` ”.TheconstructsSˆ andGˆ arenot recognizedbyas,astheyarebytheDECMACRO-32assembler.Itispreferredtousethe“` ”displacementsothatthe“ˆ ”isnotmisinterpretedasthexoroperator. Literalvalues(includingfloating-pointliteralsusedwherethehardwareexpectsafloating-pointoperand)areassembledasshortliteralsifpossible,hencenotneedingtheSˆ DEC MACRO-32directive. Ifthedisplacementlengthmodifierispresent,thenthedisplacementisalwaysassembled withthatdisplacement,evenifitwillfitintoasmallerfield,orifsignificanceislost.Ifthe lengthmodifierisnotpresent,andifthevalueofthedisplacementisknownexactlyinas’sfirst pass,thenasdeterminesthelengthautomatically,assemblingitintheshortestpossibleway, Otherwise,aswillusethevaluespecifiedbythe−dargument,whichdefaultsto4bytes. 8.3.casexInstructions Asconsiderstheinstructionscaseb,casel,casewtohavethreeoperands.Thedisplacementsmustbeexplicitlycomputedbyas,usingoneormore.wordstatements. 10 February9,1983 BerkeleyVAX/UNIXAssemblerReferenceManual 11 8.4.Extendedbranchinstructions Theseopcodes(formedingeneralbysubstitutinga“j”fortheinitial“b”ofthestandard opcodes)takeasbranchdestinationsthenameofalabelinthecurrentsubsegment.Itisan errorifthedestinationisknowntobeinadifferentsubsegment,anditisawarningifthedestinationisnotdefinedwithintheobjectmodulebeingassembled. Ifthebranchdestinationiscloseenough,thenthecorrespondingshortbranch“b” instructionisassembled.Otherwisetheassemblerchosesasequenceofoneormoreinstructions whichtogetherhavethesameeffectasifthe“b”instructionhadalargerspan.Ingeneral,as choosestheinversebranchfollowedbyabrw,butabrwissometimespooledamongseveral “j”instructionswiththesamedestination. Asisunabletoperformthesamelong/shortbranchgenerationforotherinstructionswith afixedbytedisplacement,suchasthesob,aobfamilies,orfortheacbxfamilyofinstructions whichhasafixedworddisplacement.Thiswouldbedesirable,butisprohibitivebecauseofthe complexityoftheseinstructions. Ifthe−Jassembleroptionisgiven,ajmpinstructionisusedinsteadofabrwinstructionforALL“j”instructionswithdistantdestinations.Thismakesassemblyoflarge(>32K bytes)programs(inefficiently)possible.Asdoesnottrytouseclevercombinationsofbrb, brwandjmpinstructions.ThejmpinstructionsusePCrelativeaddressing,withthelength oftheoffsetgivenbythe−dassembleroption. Thesearetheextendedbranchinstructionsasrecognizes: Notethatjbrturnsintobrbifitstargetiscloseenough;otherwiseabrwisused. 9.Diagnostics Diagnosticsareintendedtobeselfexplanatoryandappearonthestandardoutput.Diagnosticseitherreportanerrororawarning.Errordiagnosticscomplainaboutlexical,syntactic andsomesemanticerrors,andaborttheassembly. ThemajorityofthewarningscomplainabouttheuseofVAXfeaturesnotsupportedbyall implementationsofthearchitecture.Aswillwarnifnewopcodesareused,if“G”or“H”floatingpointnumbersareusedandwillcomplainaboutmixedfloatingconversions. 10.Limits 11.AnnoyancesandFutureWork Mostoftheannoyancesdealwithrestrictionsontheextendedbranchinstructions. Asonlyusesatwolevelalgorithmforresolvingextendedbranchinstructionsintoshortor longdisplacements.Whatisreallyneededisageneralmechanismtoturnashortconditional jumpintoareverseconditionaljumpoveroneoftwopossibleunconditionalbranches,eithera brworajmpinstruction.Currently,the−Jforcesthejmpinstructiontoalwaysbeused, insteadoftheshorterbrwinstructionwhenneeded. Theassemblershouldalsorecognizeextendedbranchinstructionsforsob,aob,andacbx instructions.Sobinstructionswillbeeasy,aobwillbeharderbecausethesynthesizedinstructionusestheindexoperandtwice,soonemustbecarefulofsideeffects,andtheacbxfamilywill bemuchharder(inthegeneralcase)becausethecomparisondependsonthesignoftheaddend 3AlthoughthenumberofcharactersavailabletotheargvlineisrestrictedbyUNIXto10240. February9,1983 11 12 BerkeleyVAX/UNIXAssemblerReferenceManual operand,andtwooperandsareusedmorethanonce.Augmentingaswiththeseextendedloop instructionswillallowthepeepholeoptimizertoproducemuchbetterloopoptimizations,sinceit currentlyassumestheworstcaseaboutthesizeoftheloopbody. Thestringtemporaryfileisnotputinmemorywhenthe-Vflagisset.Thestringtablein thegenerateda.outcontainssomestringsandnamesthatareneverreferencedfromthesymbol table;theloaderremovestheseunreferencedstrings,however. 12 February9,1983