📄 mdk_mixvm.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_mixvm.texi,v 1.11 2002/04/08 00:26:37 jao Exp $@node mixvm, gmixvm, mixasm, Top@comment node-name, next, previous, up@chapter @code{mixvm}, the MIX computer simulator@cindex mixvmThis chapter describes @code{mixvm}, the MIX computersimulator. @code{mixvm} is a command line interface programme whichsimulates the MIX computer (@pxref{The MIX computer}). It is ableto run MIXAL programs (@pxref{MIXAL}) previously compiled with the MIXassembler (@pxref{mixasm}). The simulator allows inspection of the MIXcomputer components (registers, memory cells, comparison flag and overflowtoggle), step by step execution of MIX programmes, and breakpointsetting to aid you in debugging your code. For a tutorial description of@code{mixvm} usage, @xref{Running the program}.@menu* Invocation:: Options when invoking @code{mixvm}.* Commands:: Commands available in interactive mode.* Devices:: MIX block devices implementation.@end menu@node Invocation, Commands, mixvm, mixvm@comment node-name, next, previous, up@section Invoking @code{mixvm}@code{mixvm} can be invoked with the following command line options(note that, following GNU's conventions, we provide a long option namefor each available single letter switch):@examplemixvm [-vhurdtq] [--version] [--help] [--usage] [--run] [--dump] [--time] [--noinit] [FILE[.mix]]@end example@noindentThe meaning of these options is as follows:@defopt -v@defoptx --versionPrints version and copyleft information and exits.@end defopt@defopt -h@defoptx --help@defoptx -u@defoptx --usagePrints a summary of available options and exits.@end defopt@defopt -r@defoptx --runLoads the specified @var{FILE} and executes it. After the programexecution, @code{mixvm} exits. @var{FILE} must be the name of a binary@file{.mix} program compiled with @code{mixasm}. If your program doesnot produce any output, use the @code{-d} flag (see below) to peek atthe virtual machine's state after execution.@end defopt@defopt -d@defoptx --dumpThis option must be used in conjuction with @code{-r}, and tells@code{mixvm} to print the value of the virtual machine's registers,comparison flag and overflow toggle after executing the program named@var{FILE}. See @xref{Non-interactive mode}, for sample usage.@end defopt@defopt -t@defoptx --timeThis option must be used in conjuction with @code{-r}, and tells@code{mixvm} to print virtual time statistics for the program'sexecution.@end defoptWhen run without the @code{-r} flag, @code{mixvm} enters its interactivemode, showing you a prompt like this one:@exampleMIX >@end example@noindentand waiting for your commands (@pxref{Commands}). If theoptional @var{FILE} argument is given, the file @file{FILE.mix} will beloaded into the virtual machine memory before entering the interactivemode. The first time @code{mixvm} is invoked, a directory named @file{.mdk} iscreated in your home directory. It contains the @code{mixvm}configuration file, the command history file and (by default) the blockdevices files (@pxref{Devices}). Before showing you the command prompt,@code{mixvm} looks in the @file{~/.mdk} directory for a file named@code{mixguile.scm}; if it exists, it is read and evaluated by theembedded Guile interpreter (@pxref{Defining new functions}). You can usethe @code{-q} command line option to skip this file loading:@defopt -q@defoptx --noinitDo not load the Guile initialisation file @code{~/.mdk/mixguile.scm} atstartup. @end defopt@node Commands, Devices, Invocation, mixvm@comment node-name, next, previous, up@section Interactive commands You can enter the interactive mode of the MIX virtual machine by simplyinvoking @code{mixvm} without arguments. You will then presented a shellprompt@footnote{The default command prompt, @samp{MIX > }, can bechanged using the @code{prompt} command (@pxref{Configuration commands})}@exampleMIX >@end example@noindentwhich indicates that a new virtual machine has been initialised and isready to execute your commands. As we have already mentioned, thiscommand prompt offers you command line editing facilities which aredescribed in the Readline user's manual (chances are that you arealready familiar with these command line editing capabilities, as theyare present in many GNU utilities, e.g. the @code{bash}shell)@footnote{The readline functionality will be available if you havecompiled @sc{mdk} with readline support, i.e., if GNU readline isinstalled in your system. This is ofte the case in GNU/Linux and BSDsystems}. In a nutshell, readline provides command completion using the@kbd{TAB} key and command history using the cursor keys. A history filecontaining the last commands typed in previous sessions is stored in the@sc{mdk} configuration directory (@file{~/.mdk}).As a beginner, your best friend will be the @code{help} command, whichshows you a summary of all available MIX commands and their usage; itssyntax is as follows:@deffn {@code{mixvm} command} help [command]Prints a short description of the given @var{command} and its usage. If@var{command} is omitted, @code{help} prints the short description forall available commands.@end deffn@menu* File commands:: Loading and executing programs.* Debug commands:: Debugging programs.* State commands:: Inspecting the virtual machine state.* Configuration commands:: Changing and storing mixvm settings.* Scheme commands:: @end menu@node File commands, Debug commands, Commands, Commands@subsection File commandsYou have at your disposal a series of commands that let you load andexecute MIX executable files, as well as manipulate MIXAL source files:@deffn {file command} load file[.mix]This command loads a binary file, @var{file.mix} into the virtualmachine memory, and positions the program counter at the beginning ofthe loaded program. This address is indicated in the MIXAL source fileas the operand of the @code{END} pseudoinstruction. Thus, if your@file{sample.mixal} source file contains the line:@example END 3000@end example@noindentand you compile it with @code{mixasm} to produce the binary file@file{sample.mix}, you will load it into the virtual machine as follows:@exampleMIX > load sampleProgram loaded. Start address: 3000MIX >@end example@end deffn@deffn {file command} run [file[.mix]]When executed without argument, this command initiates or resumesexecution of instructions from the current program counteraddress. Therefore, issuing this command after a successful @code{load},will run the loaded program until either a @code{HLT} instruction or abreakpoint is found. If you provide a MIX filename as argument, thegiven file will be loaded (as with @code{load} @var{file}) andexecuted. If @code{run} is invoked again after program executioncompletion (i.e., after the @code{HLT} instruction has been found in aprevious run), the program counter is repositioned and execution startsagain from the beginning (as a matter of fact, a @code{load} commandpreserving the currently set breakpoints is issued before resumingexecution).@end deffn@deffn {file command} edit [file[.mixal]]The source file @var{file.mixal} is edited using the editor defined inthe environment variable @var{MDK_EDITOR}. If this variable is not set,the following ones are tried out in order: @var{X_EDITOR}, @var{EDITOR}and @var{VISUAL}. If invoked without argument, the source file for thecurrently loaded MIX file is edited. The command used to edit sourcefiles can also be configured using the @code{sedit} command(@pxref{Configuration commands}).@end deffn@deffn {file command} compile file[.mixal]The source file @var{file.mixal} is compiled (with debug informationenabled) using @code{mixasm}. If invoked without argument, the sourcefile for the currently loaded MIX file is recompiled. The compilationcommand can be set using the @code{sasm} command (@pxref{Configurationcommands}). @end deffn@deffn {file command} pprog@deffnx {file command} psrcPrint the path of the currently loaded MIX program and its source file:@exampleMIX > load ../samples/primesProgram loaded. Start address: 3000MIX > pprog ../samples/primes.mixMIX > psrc/home/jao/projects/mdk/gnu/samples/primes.mixalMIx>@end example@end deffnFinally, you can use the @code{quit} command to exit @code{mixvm}:@deffn {file command} quitExit @code{mixvm}, saving the current configuration parameters in@file{~/.mdk/mixvm.config}.@end deffn@node Debug commands, State commands, File commands, Commands@subsection Debug commandsSequential execution of loaded programs can be interrupted using thefollowing debug commands:@deffn {debug command} next [ins_number]This command causes the virtual machine to fetch and execute up to@var{ins_number} instructions, beginning from the current programcounter position. Execution is interrupted either when the specifiednumber of instructions have been fetched or a breakpoint is found,whatever happens first. If run without arguments, one instruction isexecuted. If @code{next} is invoked again after program executioncompletion (i.e., after the @code{HLT} instruction has been found in aprevious run), the program counter is repositioned and execution startsagain from the beginning (as a matter of fact, a @code{load} commandpreserving the currently set breakpoints is issued before resumingexecution).@end deffn@deffn {debug command} sbp line_number@deffnx {debug command} cbp line_noSets a breakpoint at the specified source file line number. If the linespecified corresponds to a command or to a MIXAL pseudoinstruction whichdoes not produce a MIX instruction in the binary file (such as@code{ORIG} or @code{EQU}) the breakpoint is set at the first sourcecode line giving rise to a MIX instruction after the specifiedone. Thus, for our sample @file{hello.mixal} file:@example* (1)* hello.mixal: say 'hello world' in MIXAL (2)* (3)* label ins operand comment (4)TERM EQU 19 the MIX console device number (5) ORIG 1000 start address (6)START OUT MSG(TERM) output data at address MSG (7)...@end example@noindenttrying to set a breakpoint at line 5, will produce the following result:@exampleMIX > sbp 5Breakpoint set at line 7MIX > @end example@noindentsince line 7 is the first one compiled into a MIX instruction (ataddress 3000). In order to @code{sbp} to work, the source file must becompiled using the @code{-g} flags, which tells @code{mixasm} to includedebug information in the binary @file{.mix} file.The command @code{cbp} clears a (previously set) breakpoint at the givensource file line.@end deffn@deffn {debug command} spba address@deffnx {debug command} cbpa addressSets a breakpoint at the given memory @var{address}. The argument mustbe a valid MIX memory address, i.e., it must belong into the range@w{[0-3999]}. Note that no check is performed to verify that thespecified address is reachable during program execution. No debuginformation is needed to set a breakpoint by address with @code{sbpa}.The command @code{cbpa} clears a (previously set) breakpoint at thegiven memory address.@end deffn@deffn {debug command} sbpr A | X | J | Ii@deffnx {debug command} cbpr A | X | J | IiSets a conditional breakpoint on the specified register change. Forinstance, @examplesbpr I1@end example@noindentwill cause an interruption during program execution whenever thecontents or register @code{I1} changes. A previously set breakpoint iscleared using the @code{cbpr} command.@end deffn@deffn {debug command} sbpm address@deffnx {debug command} cbpm addressSets a conditional breakpoint on the specified memory cell change. Theargument must be a valid MIX memory address, i.e., it must belong intothe range @w{[0-3999]}. For instance,@examplesbpm 1000@end example@noindentwill cause an interruption during program execution whenever thecontents or of the memory cell number 1000 changes. A previously setbreakpoint is cleared using the @code{cbpm} command.@end deffn@deffn {debug command} sbpo @deffnx {debug command} cbpo Sets/clears a conditional breakpoint on overflow toggle change.@end deffn@deffn {debug command} sbpc @deffnx {debug command} cbpc Sets/clears a conditional breakpoint on comparison flag change.@end deffn@deffn {debug command} cabpClears all currently set breakpoints.@end deffn@deffn {debug command} psym [symbol_name]MIXAL programs can define symbolic constants, using either the@code{EQU} pseudoinstruction or a label at the beginning of aline. Thus, in the program fragment@exampleVAR EQU 2168 ORIG 4000START LDA VAR@end example@noindentthe symbol @code{VAR} stands for the value 2168, while @code{START} isassigned the value 4000. When MIXAL programs are compiled using the@code{-g} flag (which tells @code{mixasm} to include debug informationin the binary @file{.mix} file), the symbol table can be consulted fromthe @code{mixvm} command line using @code{psym} followed by the name ofthe symbol whose contents you are interested in. When run withoutarguments, @code{psym} will print all defined symbols and their values.@end deffnThe virtual machine can also show you the instructions it is executing,using the following commands:@deffn {debug command} strace [on|off]@code{strace on} enables instruction tracing. When tracing is enabled,each time the virtual machine executes an instruction (due to yourissuing a @code{run} or @code{next} command), it is printed in itscanonical form (that is, with all expressions evaluated to theirnumerical values) and, if the program was compiled with debuginformation, as it was originally typed in the MIXAL sourcefile. Instruction tracing is disabled with @code{strace off}command. A typical tracing session could be like this:@exampleMIX > strace onMIX > next
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -