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

📄 mdk_tut.texi

📁 汇编语言编程源代码
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
OPCODE = 15, MOD = fspec. @code{rX <- V}.@item LDiPut in rIi the contents of cell no. M.OPCODE = 8 + i, MOD = fspec. @code{rIi <- V}.@item LDANPut in rA the contents of cell no. M, with opposite sign.OPCODE = 16, MOD = fspec. @code{rA <- -V}.@item LDXNPut in rX the contents of cell no. M, with opposite sign.OPCODE = 23, MOD = fspec. @code{rX <- -V}.@item LDiNPut in rIi the contents of cell no. M, with opposite sign.OPCODE = 16 + i, MOD = fspec. @code{rIi <- -V}.@end ftableIn all the above load instructions the @samp{MOD} field selects thebytes of the memory cell with address @samp{M} which are loaded into therequisite register (indicated by the @samp{OPCODE}).  For instance, theword @w{@samp{+ 00 13 01 27 11}} represents the instruction@exampleLD3    13,1(3:3) ^      ^ ^  ^ |      | |  | |      | |   --- MOD = 27 = 3*8 + 3 |      |  --- INDEX = 1 |       --- ADDRESS = 00 13  --- OPCODE = 11@end exampleLet us suppose that, prior to this instruction execution, the state ofthe MIX computer is the following:@example[rI1] = - 00 01[rI3] = + 24 12[12] = - 01 02 03 04 05@end example@noindentAs, in this case, @w{@samp{M = 13 + [rI1] = 12}}, we have@exampleV = [M](3:3) = (- 01 02 03 04 05)(3:3)  = + 00 00 00 00 03@end example@noindent(note that the specified subfield is left-padded with null bytes tocomplete a word). Hence, the MIX state, after the instruction execution,will be@example[rI1] = - 00 01[rI3] = + 00 03[12] = - 01 02 03 04 05@end exampleTo further illustrate loading operators, the following table shows thecontents of @samp{rX} after different @samp{LDX} instructions:@table @samp@item LDX 12(0:0)     [rX] = - 00 00 00 00 00@item LDX 12(0:1)     [rX] = - 00 00 00 00 01@item LDX 12(3:5)     [rX] = + 00 00 03 04 05@item LDX 12(3:4)     [rX] = + 00 00 00 03 04@item LDX 12(0:5)     [rX] = - 01 02 03 04 05@end table@node Storing operators, Arithmetic operators, Loading operators, MIX instruction set@comment  node-name,  next,  previous,  up@subsubsection Storing operators@cindex storing operatorsThe following instructions are the inverse of the loadoperations: they are used to store a subfield of a registerinto a memory location. Here, MOD represents the subfield of the memorycell that is to be overwritten with bytes from a register. These bytesare taken beginning by the rightmost side of the register.@ftable @code@item STAStore rA. OPCODE = 24, MOD = fspec. @code{V <- rA}.@item STXStore rX. OPCODE = 31, MOD = fspec. @code{V <- rX}.@item STiStore rIi. OPCODE = 24 + i, MOD = fspec. @code{V <- rIi}.@item STJStore rJ. OPCODE = 32, MOD = fspec. @code{V <- rJ}.@item STZStore zero. OPCODE = 33, MOD = fspec. @code{V <- 0}.@end ftableBy way of example, consider the instruction @samp{STA 1200(2:3)}. Itcauses the MIX to fetch bytes no. 4 and 5 of register A and copy them tobytes 2 and 3 of memory cell no. 1200 (remember that, for theseinstructions, MOD specifies a subfield of @emph{the memoryaddress}). The other bytes of the memory cell retain theirvalues. Thus, if prior to the instruction execution we have@example[1200] = - 20 21 22 23 24[rA] = + 01 02 03 04 05@end example@noindentwe will end up with@example[1200] = - 20 04 05 23 24[rA] = + 01 02 03 04 05@end exampleAs a second example, @samp{ST2 1000(0)} will set the sign of@samp{[1000]} to that of @samp{[rI2]}.@node Arithmetic operators, Address transfer operators, Storing operators, MIX instruction set@comment  node-name,  next,  previous,  up@subsubsection Arithmetic operators@cindex arithmetic operatorsThe following instructions perform arithmetic operations between rA andrX register and memory contents.@ftable @code@item ADDAdd and set OV if overflow. OPCODE = 1, MOD = fspec. @w{@code{rA <- rA +V}}.@item SUBSub and set OV if overflow. OPCODE = 2, MOD = fspec.@w{@code{rA <- rA - V}}.@item MULMultiply V times rA and store the 10-bytes product in rAX.OPCODE = 3, MOD = fspec. @w{@code{rAX <- rA x V}}.@item DIVrAX is considered a 10-bytes number, and it is divided by V.OPCODE = 4, MOD = fspec. @w{@code{rA <- rAX / V}}, @code{rX} <- reminder.@end ftableIn all the above instructions, @samp{[rA]} is one of the operandsof the binary arithmetic operation, the other being @samp{V} (that is,the specified subfield of the memory cell with address @samp{M}), paddedwith zero bytes on its left-side to complete a word. In multiplicationand division, the register @samp{X} comes into play as a right-extensionof the register @samp{A}, so that we are able to handle 10-byte numberswhose more significant bytes are those of @samp{rA} (the sign of this10-byte number is that of @samp{rA}: @samp{rX}'s sign is ignored).Addition and substraction of MIX words can give rise to overflows, sincethe result is stored in a register with room to only 5 bytes (plussign). When this occurs, the operation result modulo @w{1,073,741,823}(the maximum value storable in a MIX word) is stored in @samp{rA}, andthe overflow toggle is set to TRUE.@node Address transfer operators, Comparison operators, Arithmetic operators, MIX instruction set@comment  node-name,  next,  previous,  up@subsubsection Address transfer operators@cindex address transfer operatorsIn these instructions, @samp{M} (the address of the instruction afterindexing) is used as a number instead of as the address of a memorycell. Consequently, @samp{M} can have any valid word value (i.e., it'snot limited to the 0-3999 range of a memory address).@ftable @code@item ENTAEnter @samp{M} in [rA]. OPCODE = 48, MOD = 2. @code{rA <- M}.@item ENTXEnter @samp{M} in [rX]. OPCODE = 55, MOD = 2. @code{rX <- M}.@item ENTiEnter @samp{M} in [rIi]. OPCODE = 48 + i, MOD = 2. @code{rIi <- M}.@item ENNAEnter @samp{-M} in [rA]. OPCODE = 48, MOD = 3. @code{rA <- -M}.@item ENNXEnter @samp{-M} in [rX]. OPCODE = 55, MOD = 3. @code{rX <- -M}.@item ENNiEnter @samp{-M} in [rIi]. OPCODE = 48 + i, MOD = 3. @code{rIi <- -M}.@item INCAIncrease [rA] by @samp{M}. OPCODE = 48, MOD = 0. @code{rA <- rA + M}.@item INCXIncrease [rX] by @samp{M}. OPCODE = 55, MOD = 0. @code{rX <- rX + M}.@item INCiIncrease [rIi] by @samp{M}. OPCODE = 48 + i, MOD = 0. @code{rIi <- rIi + M}.@item DECADecrease [rA] by @samp{M}. OPCODE = 48, MOD = 1. @code{rA <- rA - M}.@item DECXDecrease [rX] by @samp{M}. OPCODE = 55, MOD = 0. @code{rX <- rX - M}.@item DECiDecrease [rIi] by @samp{M}. OPCODE = 48 + i, MaOD = 0. @code{rIi <- rIi - M}.@end ftableIn the above instructions, the subfield @samp{ADDRESS} acts as animmediate (indexed) operand, and allow us to set directly the contentsof the MIX registers without an indirection to the memory cells (in areal CPU this would mean that they are faster that the previouslydiscussed instructions, whose operands are fetched from memory). So, ifyou want to store in @samp{rA} the value -2000 (- 00 00 00 31 16), youcan use the binary instruction @w{+ 31 16 00 03 48}, or, symbolically,@exampleENNA 2000@end example@noindentUsed in conjuction with the store operations (@samp{STA}, @samp{STX},etc.), these instructions also allow you to set memory cells contents toconcrete values.Note that in these address transfer operators, the @samp{MOD} field isnot a subfield specificator, but serves to define (together with@samp{OPCODE}) the concrete operation to be performed.@node Comparison operators, Jump operators, Address transfer operators, MIX instruction set@comment  node-name,  next,  previous,  up@subsubsection Comparison operators@cindex comparison operatorsSo far, we have learned how to move values around between the MIXregisters and its memory cells, and also how to perform arithmeticoperations using these values. But, in order to write non-trivialprograms, other functionalities are needed. One of the most common isthe ability to compare two values, which, combined with jumps, willallow the execution of conditional statements.The following instructions compare the value of a register with @samp{V}, andset the @sc{cm} indicator to the result of the comparison (i.e. to@samp{E}, @samp{G} or @samp{L}, equal, greater or lesser respectively).@ftable @code@item CMPACompare [rA] with V. OPCODE = 56, MOD = fspec.@item CMPXCompare [rX] with V. OPCODE = 63, MOD = fspec.@item CMPiCompare [rIi] with V. OPCODE = 56 + i, MOD = fspec.@end ftableAs explained above, these instructions modify the value of the MIXcomparison indicator; but maybe you are asking yourself how do you usethis value: enter jump operators, in the next subsection.@node Jump operators, Input-output operators, Comparison operators, MIX instruction set@comment  node-name,  next,  previous,  up@subsubsection Jump operators@cindex jump operatorsThe MIX computer has an internal register, called the @dfn{locationcounter}, which stores the address of the next instruction to be fetchedand executed by the virtual CPU. You cannot directly modify the contentsof this internal register with a load instruction: after fetching thecurrent instruction from memory, it is automatically increased in oneunit by the MIX. However, there is a set of instructions (which we calljump instructions) which can alter the contents of the location counterprovided some condition is met. When this occurs, the value of the nextinstruction address that would have been fetched in the absence of thejump is stored in @samp{rJ} (except for @code{JSJ}), and the locationcounter is set to the value of @samp{M} (so that the next instruction isfetched from this new address). Later on, you can return to the pointwhen the jump occurred reading the address stored in @samp{rJ}.The MIX computer provides the following jump instructions:With these instructions you force a jump to the specified address. Use@samp{JSJ} if you do not care about the return address.@ftable @code@item JMPUnconditional jump. OPCODE = 39, MOD = 0.@item JSJUnconditional jump, but rJ is not modified. OPCODE = 39, MOD = 1.@end ftableThese instructions check the overflow toggle to decide whether to jumpor not.@ftable @code@item JOVJump if OV is set (and turn it off). OPCODE = 39, MOD = 2.@item JNOVJump if OV is not set (and turn it off). OPCODE = 39, MOD = 3.@end ftableIn the following instructions, the jump is conditioned to the contents of thecomparison flag:@ftable @code@item JLJump if @w{@code{[CM] = L}}. OPCODE = 39, MOD = 4.@itemx JEJump if @w{@code{[CM] = E}}. OPCODE = 39, MOD = 5.@itemx JGJump if @w{@code{[CM] = G}}. OPCODE = 39, MOD = 6.@itemx JGEJump if @code{[CM]} does not equal @code{L}. OPCODE = 39, MOD = 7.@itemx JNEJump if @code{[CM]} does not equal @code{E}. OPCODE = 39, MOD = 8.@itemx JLEJump if @code{[CM]} does not equal @code{G}. OPCODE = 39, MOD = 9.@end ftableYou can also jump conditioned to the value stored in the MIX registers,using the following instructions:@ftable @code@item JAN@itemx JAZ@itemx JAP@itemx JANN@itemx JANZ@itemx JANPJump if the content of rA is, respectively, negative, zero, positive,non-negative, non-zero or non-positive. OPCODE = 40, MOD = 0, 1, 2, 3, 4, 5.@item JXN@itemx JXZ@itemx JXP@itemx JXNN@itemx JXNZ@itemx JXNPJump if the content of rX is, respectively, negative, zero, positive,non-negative, non-zero or non-positive. OPCODE = 47, MOD = 0, 1, 2, 3, 4, 5.@item JiN@itemx JiZ@itemx JiP@itemx JiNN@itemx JiNZ@itemx JiNPJump if the content of rIi is, respectively, negative, zero, positive,non-negative, non-zero or non-positive. OPCODE = 40 + i, MOD = 0, 1, 2, 3, 4, 5.

⌨️ 快捷键说明

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