⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdk_tut.texi

📁 汇编语言编程源代码
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
compiled program (that is, the address at which the virtual MIX machinemust begin fetching instructions after loading the program). It is alsovery common (although not mandatory) to include at least an @code{ORIG}directive to mark the initial value of the assembler's location counter(remember that it stores the address associated with each compiled MIXinstruction). Thus, a minimal MIXAL program would be@example          ORIG  2000    set the initial compilation adress          NOP           this instruction will be loaded at adress 2000          HLT           and this one at address 2001          END   2000    end of program; start at address 2000this line is not parsed by the assembler@end example@noindentThe assembler will generate two binary instructions (@code{NOP} (@w{+ 0000 00 00 00}) and @code{HLT} (+ 00 00 02 05)), which will be loaded ataddresses 2000 and 2001. Execution of the program will begin at address2000. Every MIXAL program should also include a @code{HLT} instruction,which will mark the end of program execution (but not of programcompilation). The @code{EQU} directive allows the definition of symbolic names forspecific values. For instance, we could rewrite the above program asfollows:@exampleSTART     EQU   2000          ORIG  START          NOP          HLT          END   START@end example@noindentwhich would give rise to the same compiled code. Symbolic constants (orsymbols, for short) can also be implicitly defined placing them in the@code{LABEL} field of a MIXAL instruction: in this case, the assemblerassigns to the symbol the value of the location counter before compilingthe line. Hence, a third way of writing our trivial program is@example          ORIG  2000START     NOP          HLT          END   START@end exampleThe @code{CON} directive allows you to directly specify the contents ofthe memory address pointed by the location counter. For instance, whenthe assembler encounters the following code snippet@example          ORIG  1150          CON   -1823473@end example@noindentit will assign to the memory cell number 1150 the contents @w{- 00 06 6111 49} (which corresponds to the decimal value -1823473). Finally, the @code{ALF} directive let's you specify the memory contentsas a set of five (quoted) characters, which are translated by theassembler to their byte values, conforming in that way the binary wordthat is to be stored in the corresponding memory cell. This directivecomes in handy when you need to store printable messages in a memoryaddress, as in the following example:@example          OUT  MSG       MSG is not yet defined here (future reference)MSG       ALF  "THIS "   MSG gets defined here          ALF  "IS A "          ALF  "MESSA"          ALF  "GE.  "@end example@noindentThe above snippet also shows the use of a @dfn{future reference}, thatis, the usage of a symbol (@code{MSG} in the example) prior of its actualdefinition. The MIXAL assembler is able to handle future referencessubject to some limitations which are described in the following section(@pxref{Expressions}).@cindex commentsAny line starting with an asterisk is treated as a comment and ignoredby the assembler.@example* This is a comment: this line is ignored.    * This line is an error: * must be in column 1.@end exampleAs noted in the previous section, comments can also be located after the@code{OPERAND} field of an instruction, separated from it by whitespace, as in@exampleLABEL     LDA   100  This is also a comment@end example@node Expressions, W-expressions, MIXAL directives, MIXAL@comment  node-name,  next,  previous,  up@subsection Expressions@cindex operator@cindex binary operator@cindex unary operatorThe @code{ADDRESS}, @code{INDEX} and @code{MOD} fields of a MIXALinstruction can be expressions, formed by numbers, identifiers andbinary operators (@code{+ - * / // :}). @code{+} and @code{-} can alsobe used as unary operators. Operator precedence is from left to right:there is no other operator precedence rule, and parentheses cannot beused for grouping. A stand-alone asterisk denotes the current memorylocation; thus, for instance,@example     4+2**@end example@noindentevaluates to 6 (4 plus 2) times the current memory location. White spaceis not allowed within expressions.The special binary operator @code{:} has the same meaning as in fspecs,i.e.,@exampleA:B = 8*A + B@end example@noindentwhile @code{A//B} stands for the quotient of the ten-byte number @w{@code{A} 0000 00 00 00} (that is, A right-padded with 5 null bytes or, what amountsto the same, multiplied by 64 to the fifth power) divided by@code{B}. Sample expressions are:@example18-8*3 = 3014/3 = 41+3:11 = 4:11 = 431//64 = (01 00 00 00 00)/(00 00 00 01 00) = (01 00 00 00 00)@end example@noindentNote that all MIXAL expressions evaluate to a MIX word (by definition).All symbols appearing within an expression must be previously defined. Futurereferences are only allowed when appearing standalone (or modified byan unary operator) in the @code{ADDRESS} part of a MIXAL instruction,e.g.@example* OK: stand alone future reference          STA  -S1(1:5)* ERROR: future reference in expression         LDX  2-S1S1       LD1  2000@end example@node W-expressions, Local symbols, Expressions, MIXAL@comment  node-name,  next,  previous,  up@subsection W-expressions@cindex w-expressionsBesides expressions, as described above (@pxref{Expressions}), the MIXALassembler is able to handle the so called @dfn{w-expressions} as theoperands of the directives @code{ORIG}, @code{EQU}, @code{CON} and@code{END} (@pxref{MIXAL directives}). The general form of aw-expression is the following:@example     WEXP = EXP[(EXP)][,WEXP]@end example@noindentwhere @code{EXP} stands for an expression and square brackets denoteoptional items. Thus, a w-expression is made by an expression, followedby an optional expression between parenthesis, followed by any numberof similar constructs separated by commas. Sample w-expressions are:@example2000235(3)S1+3(S2),3000S1,S2(3:5),23@end exampleW-expressions are evaluated from left to right as follows:@itemize@itemStart with an accumulated result @samp{w} equal to 0.@itemTake the first expression of the comma-separated list and evaluateit. For instance, if the w-expression is @samp{S1+2(2:4),2000(S2)}, weevaluate first @samp{S1+2}; let's suppose that @samp{S1} equals265230: then @samp{S1+2 = 265232 = + 00 01 00 48 16}.@itemEvaluate the expression within parenthesis, reducing it to an f-specof the form @samp{L:R}. In our previous example, the expressionbetween parenthesis already has the desired form: 2:4.@itemSubstitute the bytes of the accumulated result @samp{w} designated bythe f-spec using those of the previous expression value. In our sample,@samp{w = + 00 00 00 00 00}, and we must substitute bytes 2, 3 and 4 of@samp{w} using values from 265232. We need 3 bytes, and we take theleast significant ones: 00, 48, and 16, and insert them in positions2, 3 and 4 of @samp{w}, obtaining @samp{w = + 00 00 48 16 00}.@itemRepeat this operation with the remaining terms, acting on the newvalue of @samp{w}. In our example, if, say, @samp{S2 = 1:1}, we mustsubstitute the first byte of @samp{w} using one byte (the leastsignificant) from 2000, that is, 16 (since 2000 = + 00 00 00 31 16)and, therefore, we obtain @samp{w = + 16 00 48 16 00}; summing up, wehave obtained @samp{265232(1:4),2000(1:1) = + 16 00 48 16 00 =268633088}.@end itemizeAs a second example, in the w-expression@example1(1:2),66(4:5)@end example@noindentwe first take two bytes from 1 (00 and 01) and store them as bytes 1 and2 of the result (obtaining @w{@samp{+ 00 01 00 00 00}}) and, afterwards,take two bytes from 66 (01 and 02) and store them as bytes 4 and 5 ofthe result, obtaining @w{@samp{+ 00 01 00 01 02}} (262210). The processis repeated for each new comma-separated example. For instance:@example1(1:1),2(2:2),3(3:3),4(4:4) = 01 02 03 04 00@end exampleAs stated before, w-expressions can only appear as the operands of MIXALdirectives taking a constant value (@code{ORIG}, @code{EQU}, @code{CON}and @code{END}). Future references are @emph{not} allowed withinw-expressions (i.e., all symbols appearing in a w-expression must bedefined before it is used).@node Local symbols, Literal constants, W-expressions, MIXAL@comment  node-name,  next,  previous,  up@subsection Local symbols@cindex local symbolsBesides user defined symbols, MIXAL programmers can use the so called@dfn{local symbols}, which are symbols of the form @code{[1-9][HBF]}. Alocal symbol @code{nB} refers to the address of the last previousoccurrence of @code{nH} as a label, while @code{nF} refers to the next@code{nH} occurrence. Unlike user defined symbols, @code{nH} can appearmultiple times in the @code{LABEL} part of different MIXALinstructions. The following code shows an instance of local symbols'usage:@example* line 11H    LDA  100* line 2: 1B refers to address of line 1, 3F refers to address of line 4      STA  3F,2(1B//2)* line 3: redefinition of 1H1H    STZ* line 4: 1B refers to address of line 33H    JMP  1B@end exampleNote that a @code{B} local symbol never refers to a definition in itsown line, that is, in the following program:@example		ORIG 1999ST		NOP3H		EQU 693H		ENTA 3B  local symbol 3B refers to 3H in previous line		HLT		END ST@end example@noindentthe contents of @samp{rA} is set to 69 and @emph{not} to 2001. Anspecially tricky case occurs when using local symbols in conjunctionwith @code{ORIG} pseudoinstructions. To wit@footnote{The author wants tothank Philip E. King for pointing these two special cases of localsymbol usage to him.},@example		ORIG 1999 ST		NOP3H		CON 10		ENT1 *		LDA 3B** rI1 is 2001, rA is 10.  So far so good!3H		ORIG 3B+1000** at this point 3H equals 2003** and the location counter equals 3000.		ENT2 *		LDX 3B** rI2 contains 3000, rX contains 2003.		HLT		END ST@end example@node Literal constants,  , Local symbols, MIXAL@comment  node-name,  next,  previous,  up@subsection Literal constants@cindex literal constantsMIXAL allows the introduction of @dfn{literal constants}, which areautomatically stored in memory addresses after the end of the program bythe assembler. Literal constants are denoted as @code{=wexp=}, where@code{wexp} is a w-expression (@pxref{W-expressions}). For instance, thecode@exampleL         EQU   5          LDA   =20-L=@end examplecauses the assembler to add after the program's end an instructionwith contents 15 (@samp{20-L}), and to assemble the above code as theinstruction @w{@code{ LDA a}}, where @code{a} stands for the addressin which the value 15 is stored. In other words, the compiled code isequivalent to the following:@exampleL         EQU  5          LDA  a@dots{}a         CON  20-L              END  start@end example

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -