📄 mdk_tut.texi
字号:
@c -*-texinfo-*-@c This is part of the GNU MDK Reference Manual.@c Copyright (C) 2000, 2001, 2002@c Free Software Foundation, Inc.@c See the file mdk.texi for copying conditions.@c $Id: mdk_tut.texi,v 1.7 2002/04/08 00:26:37 jao Exp $@node MIX and MIXAL tutorial, Getting started, Installing MDK, Top@comment node-name, next, previous, up@chapter MIX and MIXAL tutorial@cindex MIX@cindex MIXALIn the book series @cite{The Art of Computer Programming}, by D. Knuth,a virtual computer, the MIX, is used by the author (together with theset of binary instructions that the virtual CPU accepts) to illustratethe algorithms and skills that every serious programmer shouldmaster. Like any other real computer, there is a symbolic assemblerlanguage that can be used to program the MIX: the MIX assembly language,or MIXAL for short. In the following subsections you will find a tutorialon these topics, which will teach you the basics of the MIX architectureand how to program a MIX computer using MIXAL.@menu* The MIX computer:: Architecture and instruction set of the MIX computer.* MIXAL:: The MIX assembly language.@end menu@node The MIX computer, MIXAL, MIX and MIXAL tutorial, MIX and MIXAL tutorial@comment node-name, next, previous, up@section The MIX computerIn this section, you will find a description of the MIX computer,its components and instruction set.@menu* MIX architecture:: * MIX instruction set:: @end menu@node MIX architecture, MIX instruction set, The MIX computer, The MIX computer@comment node-name, next, previous, up@subsection MIX architecture@cindex byte@cindex MIX byte@cindex word@cindex MIX word@cindex MIX architecture@cindex MIX computer@cindex register@cindex MIX register@cindex field specification@cindex fspec@cindex instruction@cindex MIX instruction@cindex address@cindex memory cell@cindex cell@cindex memory@cindex indexThe basic information storage unit in the MIX computer is the@dfn{byte}, which stores positive values in the range 0-63 . Note that aMIX byte can be then represented as 6 bits, instead of the common 8 bitsfor a @emph{regular} byte. Unless otherwise stated, we shall use theword @dfn{byte} to refer to a MIX 6-bit byte.A MIX @dfn{word} is defined as a set of 5 bytes plus a sign. The byteswithin a word are numbered from 1 to 5, being byte number one the mostsignificant one. The sign is denoted by index 0. Graphically,@example -----------------------------------------------| 0 | 1 | 2 | 3 | 4 | 5 | -----------------------------------------------| +/- | byte | byte | byte | byte | byte | -----------------------------------------------@end example@noindentSample MIX words are @samp{- 12 00 11 01 63} and @samp{+ 12 11 34 4300}.You can refer to subfields within a word using a @dfn{fieldspecification} or @dfn{fspec} of the form ``(@var{L}:@var{R})'', where@var{L} denotes the first byte, and @var{R} the last byte of thesubfield.When @var{L} is zero, the subfield includes the word'ssign. An fspec can also be represented as a single value @code{F}, givenby @code{F = 8*L + R} (thus the fspec @samp{(1:3)}, denoting the firstthree bytes of a word, is represented by the integer 11).The MIX computer stores information in @dfn{registers}, that can storeeither a word or two bytes and sign (see below), and @dfn{memory cells},each one containing a word. Specifically, the MIX computer has 4000memory cells with addresses 0 to 3999 (i.e., two bytes are enough toaddress a memory cell) and the following registers:@cindex rA@cindex rX@cindex rJ@cindex rIn@cindex register@table @asis@item @code{rA}A register. General purpose register holding a word. Usually itscontents serves as the operand of arithmetic and storing instructions.@item @code{rX}X register. General purpose register holding a word. Often it acts as anextension or a replacement of @samp{rA}.@item @code{rJ}J (jump) register. This register stores positive two-byte values,usually representing a jump address.@item @code{rI1}, @code{rI2}, @code{rI3}, @code{rI4}, @code{rI5}, @code{rI6}Index registers. These six registers can store a signed two-bytevalue. Their contents are used as indexing values for the computation ofeffective memory addresses.@end table@cindex @sc{ov}@cindex @sc{cm}@cindex @code{un}@cindex overflow toggle@cindex comparison indicator@cindex input-output devices@noindentIn addition, the MIX computer contains:@itemize @minus@itemAn @dfn{overflow toggle} (a single bit with values @dfn{on} or@dfn{off}). In this manual, this toggle is denoted @sc{ov}.@itemA @dfn{comparison indicator} (having three values: @dfn{EQUAL},@dfn{GREATER} or @dfn{LESS}). In this manual, this indicator is denoted@sc{cm}, and its possible values are abbreviated as @dfn{E}, @dfn{G} and@dfn{L}.@itemInput-output block devices. Each device is labelled as @code{un}, where@code{n} runs from 0 to 20. In Knuth's definition, @code{u0} through@code{u7} are magnetic tape units, @code{u8} through @code{15} are disksand drums, @code{u16} is a card reader, @code{u17} is a card writer,@code{u18} is a line printer and, @code{u19} is a typewriter terminal, and @code{u20},a paper tape. Our implementation maps these devices to disk files,except for @code{u19}, which represents the standard output.@end itemizeAs noted above, the MIX computer communicates with the external world bya set of input-output devices which can be ``connected'' to it. Thecomputer interchanges information using blocks of words whose lengthdepends on the device at hand (@pxref{Devices}). These words areinterpreted by the device either as binary information (for devices0-16), or as representing printable characters (devices 17-20). In thelast case, each MIX byte is mapped onto a character according to thefollowing table:@multitable {00} {C} {00} {C} {00} {C} {00} {C}@item 00 @tab @tab 01 @tab A @tab 02 @tab B @tab 03 @tab C@item 04 @tab D @tab 05 @tab E @tab 06 @tab F @tab 07 @tab G@item 08 @tab H @tab 09 @tab I @tab 10 @tab d @tab 11 @tab J@item 12 @tab K @tab 13 @tab L @tab 14 @tab M @tab 15 @tab N@item 16 @tab O @tab 17 @tab P @tab 18 @tab Q @tab 19 @tab R@item 20 @tab s @tab 21 @tab p @tab 22 @tab S @tab 23 @tab T@item 24 @tab U @tab 25 @tab V @tab 26 @tab W @tab 27 @tab X@item 28 @tab Y @tab 29 @tab Z @tab 30 @tab 0 @tab 31 @tab 1 @item 32 @tab 2 @tab 33 @tab 3 @tab 34 @tab 4 @tab 35 @tab 5@item 36 @tab 6 @tab 37 @tab 7 @tab 38 @tab 8 @tab 39 @tab 9@item 40 @tab . @tab 41 @tab , @tab 42 @tab ( @tab 43 @tab )@item 44 @tab + @tab 45 @tab - @tab 46 @tab * @tab 47 @tab /@item 48 @tab = @tab 49 @tab $ @tab 50 @tab < @tab 51 @tab >@item 52 @tab @@ @tab 53 @tab ; @tab 54 @tab : @tab 55 @tab '@end multitable@noindentThe value 0 represents a whitespace. Lowercase letters (d, s, p)correspond to symbols not representable as ASCII characters (uppercasedelta, sigma and gamma, respectively), and byte values 56-63 have noassociated character.Finally, the MIX computer features a virtual CPU which controls theabove components, and which is able to execute a rich set ofinstructions (constituting its machine language, similar to thosecommonly found in real CPUs), including arithmetic, logical, storing,comparison and jump instructions. Being a typical von Neumann computer,the MIX CPU fetchs binary instructions from memory sequentially (unlessa jump instruction is found), and stores the address of the nextinstruction to be executed in an internal register called @dfn{locationcounter} (also known as program counter in other architectures).The next section, @xref{MIX instruction set}, gives a complete descriptionof the available MIX binary instructions.@node MIX instruction set, , MIX architecture, The MIX computer@comment node-name, next, previous, up@subsection MIX instruction set@cindex instruction setThe following subsections fully describe the instruction set of the MIXcomputer. We begin with a description of the structure of binaryinstructions and the notation used to refer to their subfields. Theremaininig subsections are devoted to describing the actual instructionsavailable to the MIX programmer.@menu* Instruction structure:: * Loading operators:: * Storing operators:: * Arithmetic operators:: * Address transfer operators:: * Comparison operators:: * Jump operators:: * Input-output operators:: * Conversion operators:: * Shift operators:: * Miscellaneous operators:: * Execution times:: @end menu@node Instruction structure, Loading operators, MIX instruction set, MIX instruction set@comment node-name, next, previous, up@subsubsection Instruction structureMIX @dfn{instructions} are codified as words with the following subfieldstructure:@multitable @columnfractions .15 .20 .65@item @emph{Subfield} @tab @emph{fspec} @tab @emph{Description}@item ADDRESS @tab (0:2)@tab The first two bytes plus sign are the @dfn{address} field. Combinedwith the INDEX field, denotes the memory address to be used by theinstruction.@item INDEX @tab (3:3)@tab The third byte is the @dfn{index}, normally used for indexing theaddress@footnote{The actual memory address the instruction refers to, isobtained by adding to ADDRESS the value of the @samp{rI} registerdenoted by INDEX.}.@item MOD @tab (4:4)@tab Byte four is used either as an operation code modifier or as a fieldspecification.@item OPCODE @tab (5:5)@tab The last (least significant) byte in the word denotes the operationcode.@end multitable@noindentor, graphically,@example ------------------------------------------------| 0 | 1 | 2 | 3 | 4 | 5 | ------------------------------------------------| ADDRESS | INDEX | MOD | OPCODE | ------------------------------------------------@end exampleFor a given instruction, @samp{M} stands forthe memory address obtained after indexing the ADDRESS subfield (using its INDEX byte), and @samp{V} is the contents of thesubfield indicated by MOD of the memory cell with address @samp{M}. Forinstance, suppose that we have the following contents of MIX registersand memory cells:@example[rI2] = + 00 63[31] = - 10 11 00 11 22@end example@noindentwhere @samp{[n]} denotes the contents of the nth memory cell and@samp{[rI2]} the contents of register @samp{rI2}@footnote{In general,@samp{[X]} will denote the contents of entity @samp{X}; thus, bydefinition, @w{@samp{V = [M](MOD)}}.}. Let us consider the binaryinstruction @w{@samp{I = - 00 32 02 11 10}}. For this instruction wehave:@exampleADDRESS = - 00 32 = -32INDEX = 02 = 2MOD = 11 = (1:3)OPCODE = 10M = ADDRESS + [rI2] = -32 + 63 = 31V = [M](MOD) = (- 10 11 00 11 22)(1:3) = + 00 00 10 11 00@end exampleNote that, when computing @samp{V} using a word and an fspec, we applya left padding to the bytes selected by @samp{MOD} to obtain acomplete word as the result. In the following subsections, we willassing to each MIX instruction a mnemonic, or symbolic name. Forinstance, the mnemonic of @samp{OPCODE} 10 is @samp{LD2}. Thus we canrewrite the above instruction as@exampleLD2 -32,2(1:3)@end example@noindentor, for a generic instruction:@exampleMNEMONIC ADDRESS,INDEX(MOD)@end example@noindentSome instructions are identified by both the OPCODE and the MODfields. In these cases, the MOD will not appear in the above symbolicrepresentation. Also when ADDRESS or INDEX are zero, they can beomitted. Finally, MOD defaults to (0:5) (meaning thewhole word).@node Loading operators, Storing operators, Instruction structure, MIX instruction set@comment node-name, next, previous, up@subsubsection Loading operators@cindex loading operatorsThe following instructions are used to load memory contents into aregister.@ftable @code@item LDAPut in rA the contents of cell no. M.OPCODE = 8, MOD = fspec. @code{rA <- V}.@item LDXPut in rX the contents of cell no. M.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -