📄 mdk_mixvm.texi
字号:
3000: [OUT 3002,0(2:3)] START OUT MSG(TERM)MIXAL HELLO WORLD Elapsed time: 1 /Total program time: 1 (Total uptime: 1)MIX > next3001: [HLT 0,0] HLTEnd of program reached at address 3002Elapsed time: 10 /Total program time: 11 (Total uptime: 11)MIX > strace offMIX > @end example@noindentThe executed instruction, as it was translated, is shown between squarebrackets after the memory address, and, following it, you can see theactual MIXAL code that was compiled into the executed instruction. Thetracing behaviour is stored as a configuration parameter in @file{~/.mdk}.@end deffn@deffn {debug command} pline [LINE_NUMBER]Prints the requested source line (or the current one if@var{line_number} is omitted:@exampleMIX > load ../samples/helloProgram loaded. Start address: 3000MIX > plineLine 5: START OUT MSG(TERM)MIX > pline 6Line 6: HLT MIX >@end example@end deffn@deffn {debug command} pbt [INS_NUMBER]This command prints a backtrace of executed instructions. Its optionalargument @var{ins_number} is the number of instructions to print. If itis omitted or equals zero, all executed instructions are printed. Forinstance, if you compile and load the following program (@file{bt.mixal}):@example ORIG 0BEG JMP *+1 JMP *+1FOO JMP BARBAR HLT END BEG@end example@noindentyou could get the following traces:@exampleMIX > load btProgram loaded. Start address: 0MIX > nextMIX > pbt #0 BEG in bt.mixal:2MIX > nextMIX > pbt#0 1 in bt.mixal:3#1 BEG in bt.mixal:2MIX > runRunning ...... doneMIX > pbt 3#0 BAR in bt.mixal:5#1 FOO in bt.mixal:4#2 1 in bt.mixal:3MIX > pbt#0 BAR in bt.mixal:5#1 FOO in bt.mixal:4#2 1 in bt.mixal:3#3 BEG in bt.mixal:2MIX >@end exampleNote that the executed instruction trace gives you the label of theexecuted line or, if it has no label, its address.@end deffnAs you have probably observed, @code{mixvm} prints timing statisticswhen running programs. This behaviour can be controlled using the@code{stime} command (@pxref{Configuration commands}).@code{mixvm} is also able of evaluating w-expressions(@pxref{W-expressions}) using the following command:@deffn {debug command} weval WEXPEvaluates the given w-expression, @var{WEXP}. The w-expression cancontain any currently defined symbol. For instance:@exampleMIX > psym START+ 00 00 00 46 56 (0000003000)MIX > weval START(0:1),START(3:4)+ 56 00 46 56 00 (0939716096)MIX >@end example@end deffnNew symbols can be defined using the @code{ssym} command:@deffn {debug command} ssym SYM WEXPDefines the symbol named @var{SYM} with the value resulting fromevaluating @var{WEXP}, an w-expression. The newly defined symbol can beused in subsequent @code{weval} commands, as part of the expression tobe evaluated. E.g.,@exampleMIX > ssym S 2+23*START+ 00 00 18 19 56 (0000075000)MIX > psym S+ 00 00 18 19 56 (0000075000)MIX > weval S(3:4)+ 00 00 19 56 00 (0000081408)MIX > @end example@end deffnFinally, if you want to discover which is the decimal value of a MIXword expressed as five bytes plus sign, you can use@deffn {debug command} w2d WORDComputes the decimal value of the given word. @var{WORD} must beexpressed as a sign (+/-) followed by five space-delimited, two-digitdecimal values representing the five bytes composing the word. Thereverse operation (showing the word representation of a decimal value)can be accomplished with @code{weval}. For instance: @exampleMIX > w2d - 01 00 00 02 02-16777346MIX > weval -16777346- 01 00 00 02 02 (0016777346)MIX > @end example@end deffn@node State commands, Configuration commands, Debug commands, Commands@subsection State commandsInspection and modification of the virtual machine state (memory,registers, overflow toggle and comparison flag contents) is accomplishedusing the following commands:@deffn {state command} pstatThis commands prints the current virtual machine state, which can be oneof the following:@itemize @minus@itemNo program loaded@itemProgram successfully loaded@itemExecution stopped (@code{next} executed)@itemExecution stopped: breakpoint encountered@itemExecution stopped: conditional breakpoint encountered@itemProgram successfully terminated@end itemize@end deffn@deffn {state command} pcPrints the current value of the program counter, which stores theaddress of the next instruction to be executed in a non-halted program.@end deffn@deffn {state command} sreg A | X | J | I[1-6] value@deffnx {state command} preg [A | X | J | I[1-6]]@deffnx {state command} pall@code{preg} prints the contents of a given MIX register. For instance,@w{@code{preg} @var{A}} will print the contents of the A-register. Wheninvoked without arguments, all registers shall be printed:@exampleMIX > pregrA: - 00 00 00 00 35 (0000000035)rX: + 00 00 00 15 40 (0000001000)rJ: + 00 00 (0000)rI1: + 00 00 (0000) rI2: + 00 00 (0000) rI3: + 00 00 (0000) rI4: + 00 00 (0000) rI5: + 00 00 (0000) rI6: + 00 00 (0000) MIX > @end exampleAs you can see in the above sample, the contents is printed as the signplus the values of the MIX bytes stored in the register and, betweenparenthesis, the decimal representation of its module.@code{pall} prints the contents of all registers plus the comparisonflag and overflow toggle.Finally, @code{sreg} Sets the contents of the given register to@var{value}, expressed as a decimal constant. If @var{value} exceeds themaximum value storable in the given register, @code{VALUE modMAXIMU_VALUE} is stored, e.g.@exampleMIX > sreg I1 1000MIX > preg I1rI1: + 15 40 (1000) MIX > sreg I1 1000000MIX > preg I1rI1: + 09 00 (0576) MIX > @end example@end deffn@deffn {state command} pflags@deffnx {state command} scmp E | G | L@deffnx {state command} sover F | T@code{pflags} prints the value of the comparison flag and overflowtoggle of the virtual machine, e.g.@exampleMIX > pflagsOverflow: FCmp: EMIX > @end example@noindentThe values of the overflow toggle are either @var{F} (false) or @var{T}(true), and, for the comparison flag, @var{E}, @var{G}, @var{L} (equal,greater, lesser). @code{scmp} and @code{sover} are setters of thecomparison flag and overflow toggle values.@end deffn@deffn {state command} pmem from[-to]@deffnx {state command} smem address value@code{pmem} prints the contents of memory cells in the address range@w{[@var{FROM}-@var{TO}]}. If the upper limit @var{to} is omitted, onlythe contents of the memory cell with address @var{FROM} is printed, asin@exampleMIX > pmem 30003000: + 46 58 00 19 37 (0786957541)MIX >@end exampleThe memory contents is displayed both as the set of five MIX bytes plussign composing the stored MIX word and, between parenthesis, the decimalrepresentation of the module of the stored value.@code{smem} sets the content of the memory cell with address@var{address} to @var{value}, expressed as a decimal constant.@end deffn@node Configuration commands, Scheme commands, State commands, Commands@subsection Configuration commandsThis section describes commands that allow you to configure the virtualmachine behaviour. This configuration is stored in the @sc{mdk}directory @file{~/.mdk}.As you can see in their description, some commands print, as a sideeffect, informational messages to the standard output (e.g. @code{load}prints a message telling you the loaded program's start address): thesemessages can be enabled/disabled using @code{slog}:@deffn {config command} slog on|offTurns on/off the logging of informational messages. Note that errormessages are always displayed, as well as state messages required usingcommands prefixed with @code{p} (@code{preg}, @code{pmem} and the like).@end deffn@deffn {config command} stime on|off@deffnx {config command} ptime The @code{stime} command (un)sets the printing of timing statistics, and@code{ptime} prints their current value:@exampleMIX > ptimeElapsed time: 10 /Total program time: 11 (Total uptime: 11)MIX >@end example@end deffn@deffn {config command} sedit TEMPLATE@deffnx {config command} pedit@code{sedit} sets the command to be used to edit MIXAL source files withthe @code{edit} command. @var{TEMPLATE} must contain the controlcharacters @code{%s} to mark the place where the source's file name willbe inserted. For instance, if you type@exampleMIX > sedit emacsclient %sMIX >@end exampleissuing the @code{mixvm} command @w{@code{edit foo.mixal}} will invokethe operating system command @w{@code{emacsclient foo.mixal}}.@code{pedit} prints the current value of the edit command template.@end deffn@deffn {config command} sasm TEMPLATE@deffnx {config command} pasm@code{sasm} sets the command to be used to compile MIXAL source files withthe @code{compile} command. @var{template} must contain the controlcharacters @code{%s} to mark the place where the source's file name willbe inserted. For instance, if you type@exampleMIX > sasm mixasm -g -l %sMIX >@end exampleissuing the @code{mixvm} command @w{@code{compile foo.mixal}} will invokethe operating system command @w{@code{mixasm -g -l foo.mixal}}.@code{pasm} prints the current value of the compile command template.@end deffn@deffn {config command} sddir DIRNAME@deffnx {config command} pddirMIX devices (@pxref{Devices}) are implemented as regular files stored,by default, inside @file{~/.mdk}. The @code{sddir} command lets youspecify an alternative location for storing these device files, while@code{pddir} prints the current device directory.@end deffnFinally, you can change the default command prompt, @samp{MIX > },using the @code{prompt} command:@deffn {config command} prompt PROMPTChanges the command prompt to @var{prompt}. If you want to includewhite space(s) at the end of the new prompt, bracket @var{prompt} usingdouble quotes (e.g., @code{prompt ">> "}).@end deffn@node Scheme commands, , Configuration commands, Commands@subsection Scheme commandsIf you have compiled @sc{mdk} with @code{libguile} support(@pxref{Special configure flags}), @code{mixvm} will start andinitialise an embedded Guile Scheme interpret when it is invoked. Thatmeans that you have at your disposal, at @code{mixvm}'s command prompt,all the Scheme primitives described in @ref{Using mixguile} and@ref{mixguile}, as well as any other function or hook that you havedefined in the initialisation file @file{~/.mdk/mixguile.scm}. Toevaluate a Scheme function, simply type it at the @code{mixvm} commandprompt (see @ref{Using Scheme in mixvm and gmixvm} for asample). Compared to the @code{mixguile} program, this has only onelimitation: the expressions used in @code{mixvm} cannot span more thanone line. You can get over this inconvenience writing your multilineScheme expressions in a file and loading it using the @code{scmf}command:@deffn {scheme command} scmf FILE_NAMELoads the given Scheme file and evaluates it using the embedded Guileinterpreter. @end deffn@node Devices, , Commands, mixvm@section MIX block devicesThe MIX computer comes equipped with a set of block devices forinput-output operations (@pxref{Input-output operators}). @code{mixvm}implements these block devices as disk files, with the exception ofblock device no. 19 (typewriter terminal) which is redirected tostandard output. When you request an output operation on any other(output) device, a file named according to the following table will becreated, and the specified MIX words will bewritten to the file in binary form (for binary devices) or in ASCII (forchar devices). Files corresponding to input block devices should becreated and filled beforehand to be used by the MIX virtual machine (forinput-output devices this creation can be accomplished by a MIXALprogram writing to the device the required data, or, if you prefer, withyour favourite editor). The device files are stored, by default, in thedirectory @file{~/.mdk}; this location can be changed using the@code{mixvm} command @code{devdir} (@pxref{Configuration commands}).@multitable {the device name} { xx-xx } {filename[x-x].dev} {bin i/o/char } @item @emph{Device} @tab @emph{No.} @tab @emph{filename} @tab @emph{type}@item Tape @tab 0-7 @tab @file{tape[0-7].dev} @tab bin i/o@item Disks @tab 8-15 @tab @file{disk[0-7].dev} @tab bin i/o@item Card reader @tab 16 @tab @file{cardrd.dev} @tab char in@item Card writer @tab 17 @tab @file{cardwr.dev} @tab char out@item Line printer @tab 18 @tab @file{printer.dev} @tab char out@item Terminal @tab 19 @tab @code{stdout} @tab char out@item Paper tape @tab 20 @tab @file{paper.dev} @tab char out@end multitable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -