?? assembler
字號:
.\"tbl ... ^ [tn]roff -ms.hc %.TLAssembler Reference Manual.AUDennis M. Ritchie.AI.MH.SH0. Introduction.PPThis document describes the usage and input syntaxof the \s8UNIX PDP\s10-11 assembler \fIas\fP.The detailsof the \s8PDP\s10-11 are not described..PPThe input syntax of the \s8UNIX\s10 assembler is generallysimilar to that of the \s8DEC\s10 assembler \s8PAL\s10-11\s8R\s10, althoughits internal workings and output formatare unrelated.It may be useful to read the publication \s8DEC\s10-11-\s8ASDB\s10-\s8D\s10,which describes \s8PAL\s10-11\s8R\s10, although naturallyone must use care in assuming that its rules applyto \fIas\fP..PP\fIAs\fP is a rather ordinary assembler withoutmacro capabilities.It produces an output file that containsrelocation information and a completesymbol table;thus the output is acceptable to the \s8UNIX\s10 link-editor\fIld\fP, whichmay be used to combine the outputs of severalassembler runs and to obtainobject programs from libraries.The output format has been designedso that if a program contains no unresolvedref%er%ences to external symbols, it is executablewithout further processing..SH1. Usage.PP\fIas\fP is used as follows:.DSas \fR[\fB \-u \fR] [ \fB\-o \fIoutput\fR ] \fIfile\s6\d1\u\s10 .\|.\|..DEIf the optional ``\-u'' argument isgiven, all undefined symbolsin the current assembly will be made undefined-external.See the \fB.globl\fR directive below..PPThe other arguments name fileswhich are concatenated and assembled.Thus programs may be written in severalpieces and assembled together..PPThe output of the assembler is by default placed onthe file \fIa.out\fR in the current directory;the ``\-o'' flag causes the output to be placed on the named file.If there were no unresolvedexternal ref%er%ences, and no errors detected,the output file is marked executable; otherwise, if it isproduced at all, it is made non-executable..SH2. Lexical conventions.PPAssembler tokens include identifiers (alternatively, ``symbols'' or ``names''),temporary symbols,constants, and operators..SH2.1 Identifiers.PPAn identifier consists of a sequence of alphanumeric characters (includingperiod ``\|\fB.\fR\|'', underscore ``\(ul'',and tilde ``~''as alphanumeric)of which the first may notbe numeric.Only the first eight characters are significant.When a name begins with a tilde, the tilde is discardedand that occurrence of the identifier generatesa unique entry in the symbol table which can matchno other occurrence of the identifier.This feature is usedby the C compiler to place names of local variablesin the output symbol tablewithout having to worryabout making them unique..SH2.2 Temporary symbols.PPA temporary symbol consists of a digit followed by ``f\|'' or``b''.Temporary symbols are discussed fully in \(sc5.1..SH2.3 Constants.PPAn octal constant consists of a sequence of digits; ``8'' and``9'' are taken to have octal value 10 and 11.The constantis truncated to 16 bits and interpreted in two's complementnotation..PPA decimal constant consists of a sequence of digits terminatedby a decimal point ``\fB.\fR''. The magnitude of the constant should berepresentable in 15 bits; i.e., be less than 32,768..PPA single-character constant consists of a single quote ``\|\(fm\|''followed by an \s8ASCII\s10 character not a new-line.Certain dual-character escape sequencesare acceptable in place of the \s8ASCII\s10 character to representnew-line and other non-graphics (see \fIString state%ments\fP, \(sc5.5).The constant's value has the code for thegiven character in the least significantbyte of the word and is null-padded on the left..PPA double-character constant consists of a doublequote ``\|"\|'' followed by a pair of \s8ASCII\s10 charactersnot including new-line.Certain dual-character escape sequences are acceptablein place of either of the \s8ASCII\s10 charactersto represent new-line and other non-graphics(see \fIString state%ments\fR, \(sc5.5).The constant's value has the code for the firstgiven character in the least significantbyte and that for the second character inthe most significant byte..SH2.4 Operators.PPThere are several single- and double-characteroperators; see \(sc6..SH2.5 Blanks.PPBlank and tab charactersmay be interspersed freely between tokens, but maynot be used within tokens (except character constants).A blank or tab is required to separate adjacentidentifiers or constants not otherwise separated..SH2.6 Comments.PPThe character ``\|/\|'' introduces a comment, which extendsthrough the end of the line on which it appears.Comments are ignored by the assembler..SH3. Segments.PPAssembled code and datafall into three segments: the text segment, the data segment, and the bss segment.The text segment is the one in which the assembler begins,and it is the one into which instructions are typically placed.The \s8UNIX\s10 system will, if desired,enforce the purity of the text segment of programs bytrapping write operationsinto it.Object programs produced by the assembler must be processedby the link-editor \fIld\fR(using its ``\-n'' flag)if the text segment is to be write-protected.A single copy of the textsegment is shared among all processesexecuting such a program..PPThe data segment is available for placingdata or instructions whichwill be modified during execution.Anything which may go in the text segment may be putinto the data segment.In programs with write-protected, sharable text segments,data segment contains the initialized but variableparts of a program.If the text segment is not pure, the data segment beginsimmediately after thetext segment;if the text segment is pure, the data segment begins at the lowest8K byte boundary after the text segment..PPThe bss segment may not contain any explicitly initialized codeor data.The length of the bss segment (like that of text or data)is determined by the high-water mark of the location counterwithin it.The bss segment is actually an extension ofthe data segment and begins immediately after it.At the start of execution of a program, the bss segmentis set to 0.Typically the bss segment is set upby state%ments exemplified by.DSlab\fB: .\fR = \fB.\fR+10.DEThe advantage in using the bss segmentfor storage that starts off empty is that the initializationinformation need not be stored in the output file.See also \fILocation counter\fP and \fIAssignment state%ments\fPbelow..SH4. The location counter.PPOne special symbol, ``\|\fB.\fP\|'', is the location counter.Its value at any time is the offsetwithin the appropriate segment of the start ofthe state%ment in which it appears.The location counter may be assigned to,with the restriction that thecurrent segment may not change;furthermore,the value of ``\|\fB.\fP\|'' may not decrease.If the effect of the assignment is to increase the value of ``\|\fB.\fP\|'',the required number of null bytes are generated(but see \fISegments\fP above)..SH5. Statements.PPA source program is composed of a sequence of\fIstate%ments\fP.Statements are separated either by new-linesor by semicolons.There are five kinds of state%ments: null state%ments,expression state%ments, assignment state%ments,string state%ments,and keyword state%ments..PPAny kind of state%ment may be preceded byone or more labels..SH5.1 Labels.PPThere are two kinds of label:name labels and numeric labels.A name label consists of a name followedby a colon (\|:\|).The effect of a name label is to assign the currentvalue and type of the location counter ``\|\fB.\fP\|''to the name.An error is indicated in pass 1 if thename is already defined;an error is indicated in pass 2 if the ``\|\fB.\fP\|''value assigned changes the definitionof the label..PPA numeric label consists of a digit \fI0\fR to \fI9\fR followed by a colon (\|:\|).Such a label serves to define temporarysymbols of the form ``\fIn\fR\|b'' and ``\fIn\fR\|f\|'', where \fIn\fR isthe digit of the label.As in the case of name labels, a numeric label assignsthe current value and type of ``\|\fB.\fP\|'' to the temporarysymbol.However, several numeric labels with the samedigit may be used within the same assembly.Ref%er%ences of the form ``\fIn\fR\|f\|'' refer to the firstnumeric label ``\fIn\|\fR:'' \fIf\fR\|orward from the ref%er%ence;``\fIn\|\fRb'' symbols refer to the first ``\fIn\|\fR\|:'' label\fIb\|\fRackward from the ref%er%ence.This sort of temporary label was introduced by Knuth[\fIThe Art of Computer Programming, Vol I: Fundamental Algorithms\|\fR].Such labels tend to conserve both the symbol tablespace of the assembler and theinventive powers of the programmer..SH5.2 Null state%ments.PPA null state%ment is an empty state%ment (which may, however,have labels).A null state%ment is ignored by the assembler.Common examples of null state%ments are emptylines or lines containing only a label..SH5.3 Expression state%ments.PPAn expression state%ment consists of an arithmeticexpression not beginning witha keyword.The assembler computes its (16-bit) valueand places it in the output stream, together with theappropriate relocation bits..SH5.4 Assignment state%ments.PPAn assignment state%ment consists of an identifier, an equals sign (\|=\|),and an expression.The value and type of the expression are assigned tothe identifier.It is not required that the type or value bethe same in pass 2 as in pass 1, nor is it anerror to redefine any symbol by assignment..PPAny external attribute of the expression is lost acrossan assignment.This means that it is not possible to declare a globalsymbol by assigning to it, and that it is impossibleto define a symbol to be offset from a non-locallydefined global symbol..PPAs mentioned,it is permissible to assign to thelocation counter ``\|\fB.\fP\|''.It is required, however, that the type ofthe expression assigned be of the same typeas ``\|\fB.\fP\|'',and it is forbidden to decrease the valueof ``\fB\|.\|\fR''.In practice, the most common assignment to ``\|\fB.\fP\|'' has the form``.\|=\|.\|+\|\fIn\fR''for some number \fIn;\fR this has the effect of generating\fIn\fR null bytes..SH5.5 String state%ments.PPA string state%ment generates a sequence of bytes containing \s8ASCII\s10 characters.A string state%ment consists of a left string quote ``<''followed by a sequence of \s8ASCII\s10 characters not including newline,followed by a right string quote ``>''.Any of the \s8ASCII\s10 characters maybe replaced by a two-character escape sequence to representcertain non-graphic characters, as follows:.DS C.TSl l l.\en \s8NL\s10 (012)\es \s8SP\s10 (040)\et \s8HT\s10 (011)\ee \s8EOT\s10 (004)\e0 \s8NUL\s10 (000)\er \s8CR\s10 (015)\ea \s8ACK\s10 (006)\ep \s8PFX\s10 (033)\e\e \e\e> >.TE.DEThe last two are included so that the escape characterand the right string quote may be represented.The same escape sequencesmay also be used within single- and double-characterconstants (see \(sc2.3 above)..SH5.6 Keyword state%ments.PPKeyword state%ments are numerically the most common type,since most machine instructions are of thissort.A keyword state%ment begins with one of the many predefinedkeywords of the assembler;the syntax of the remainder dependson the keyword.All the keywords are listed below with the syntax they require..SH6. Expressions.PPAn expression is a sequence of symbols representing a value.Its constituents are identifiers, constants, temporary symbols,operators, and brackets.Each expression has a type..PPAll operators in expressions are fundamentally binary innature; if an operand is missing on the left, a 0of absolute type is assumed.Arithmeticis two's complement and has 16 bits of precision.All operators have equal precedence, and expressionsare evaluatedstrictly left to right except for the effectof brackets..SH6.1 Expression operators.PPThe operators are:.IP (blank) 8when there is no operand betweenoperands, the effect isexactly the same as if a ``+'' had appeared..pg.ti 0.IP + 8addition.IP \- 8subtraction.IP * 8multiplication.IP \e\(sl 8division (note that plain ``\|/\|'' starts a comment).IP 8 & 8bitwise \fBand\fR.IP \(bv 8bitwise \fBor\fR.IP \e> 8logical right shift.IP \\e< 8logical left shift.hc.IP % 8modulo.IP ! 8.hc %\fIa\fR\|!\|\fIb\fR is \fIa \fBor \fR(\|\fBnot \fIb\fR\|);i.e., the \fBor\fR of the first operand andthe one's complement of the second; most common use isas a unary..IP ^ 8result has the value of first operand and the type of the second;most often used to define new machine instructionswith syntax identical to existing instructions..PPExpressions may be grouped by use of square brackets ``\|[\|\|]\|''.(Round parentheses are reserved for address modes.).SH6.2 Types.PPThe assembler deals with a number of typesof expressions. Most typesare attached to keywords and used to select theroutine which treats that keyword. The types likelyto be met explicitly are:.IP undefined 8.brUpon first encounter, each symbol is undefined.It may become undefined if it is assigned an undefined expression.It is an error to attempt to assemble an undefinedexpression in pass 2; in pass 1, it is not (except thatcertain keywords require operands which are not undefined)..IP "undefined external" 8.brA symbol which is declared \fB.globl\fR but not definedin the current assembly is an undefinedexternal.If such a symbol is declared, the link editor \fIld\fRmust be used to load the assembler's output withanother routine that defines the undefined ref%er%ence..IP absolute 8An absolute symbol is defined ultimately from a constant.Its value is unaffected by any possible future applicationsof the link-editor to the output file..IP text 8The value of a text symbol is measuredwith respect to the beginning of the text segment of the program.If the assembler output is link-edited, its textsymbols may change in valuesince the program neednot be the first in the link editor's output.Most text symbols are defined by appearing as labels.At the start of an assembly, the value of ``\|\fB.\fP\|'' is text 0..IP data 8The value of a data symbol is measuredwith respect to the origin of the data segment of a program.Like text symbols, the value of a data symbol may changeduring a subsequent link-editor run since previouslyloaded programs may have data segments.After the first \fB.data\fR state%ment, the value of ``\|\fB.\fP\|''is data 0..IP bss 8The value of a bss symbol is measured fromthe beginning of the bss segment of a program.Like text and data symbols, the value of a bss symbolmay change during a subsequent link-editorrun, since previously loaded programs may have bss segments.After the first \fB.bss\fR state%ment, the value of ``\|\fB.\fP\|'' is bss 0..IP "external absolute, text, data, or bss" 8.brsymbols declared \fB.globl\fRbut defined within an assembly as absolute, text, data, or bsssymbols may be used exactly as if they were notdeclared \fB.globl\fR; however, their value and type are availableto the link editor so that the program may be loaded with othersthat ref%er%ence these symbols..IP register 8.brThe symbols.DS\fBr0\fR .\|.\|. \fBr5fr0\fR .\|.\|. \fBfr5sppc.DEare predefinedas register symbols.Either they or symbols defined from them mustbe used to refer to the six general-purpose,six floating-point, andthe 2 special-purpose machine registers.The behavior of the floating register namesis identical to that of the correspondinggeneral register names; the formerare provided as a mnemonic aid..IP "other types" 8.brEach keyword known to the assembler has a type whichis used to select the routine which processesthe associated keyword state%ment.The behavior of such symbolswhen not used as keywords is the same as if they were absolute..SH6.3 Type propagation in expressions.PPWhen operands are combined by expression operators,the result has a type which depends on the typesof the operands and on the operator.The rules involved are complex to state butwere intended to be sensible and predictable.For purposes of expression evaluation theimportant types are.DS
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -