📄 mdk_gstart.texi
字号:
form FROM-TO can also be used as the argument of @code{pmem}:@exampleMIX > pmem 3000-30063000: + 46 58 00 19 37 (0786957541)3001: + 00 00 00 02 05 (0000000133)3002: + 14 09 27 01 13 (0237350989)3003: + 00 08 05 13 13 (0002118477)3004: + 16 00 26 16 19 (0268542995)3005: + 13 04 00 00 00 (0219152384)3006: + 00 00 00 00 00 (0000000000)MIX >@end example@cindex @code{preg}@noindentIn a similar manner, you can look at the contents of the MIX registersand flags. For instance, to ask for the contents of the A register youcan type@exampleMIX > preg ArA: + 00 00 00 00 00 (0000000000)MIX >@end example@cindex @code{help}@noindentUse the comand @code{help} to obtain a list of all available commands,and @code{help COMMAND} for help on a specific command, e.g.@exampleMIX > help runrun Run loaded or given MIX code file. Usage: run [FILENAME]MIX > @end example@noindentFor a complete list of commands available at the MIX propmt,@xref{mixvm}. In the following subsection, you will find a quick tourover commands useful for debugging your programs.@node Debugging, , Interactive mode, Running the program@comment node-name, next, previous, up@subsection Debugging commands@cindex @code{next}The interactive mode of @code{mixvm} lets you step by step execution ofprograms as well as breakpoint setting. Use @code{next} to step throughthe program, running its instructions one by one. To run ourtwo-instruction @file{hello.mix} sample you can do the following:@exampleMIX > load helloProgram loaded. Start address: 3000MIX > pcCurrent address: 3000MIX > nextMIXAL HELLO WORLDElapsed time: 1 /Total program time: 1 (Total uptime: 1)MIX > pcCurrent address: 3001MIX > nextEnd of program reached at address 3002Elapsed time: 10 /Total program time: 11 (Total uptime: 11)MIX > pcCurrent address: 3002MIX > nextMIXAL HELLO WORLDElapsed time: 1 /Total program time: 1 (Total uptime: 12)MIX > MIX > runRunning ...... doneElapsed time: 10 /Total program time: 11 (Total uptime: 22)MIX >@end example@noindent(As an aside, the above sample also shows how the virtual machinehandles cummulative time statistics and automatic program restart).@cindex @code{sbpa}@cindex breakpointsYou can set a breakpoint at a given address using the command@code{sbpa} (set breakpoint at address). When a breakpoint is set,@code{run} will stop before executing the instruction at the givenaddress. Typing @code{run} again will resume program execution. Comingback to our hello world example, we would have:@exampleMIX > sbpa 3001Breakpoint set at address 3001MIX > runRunning ...MIXAL HELLO WORLD ... stopped: breakpoint at line 8 (address 3001)Elapsed time: 1 /Total program time: 1 (Total uptime: 23)MIX > runRunning ...... doneElapsed time: 10 /Total program time: 11 (Total uptime: 33)MIX >@end example@cindex @code{sbp}@cindex breakpoints@noindentNote that, since we compiled @file{hello.mixal} with debug info enabled(the @code{-g} flag of @code{mixasm}), the virtual machine is able totell us the line in the source file corresponding to the breakpoint weare setting. As a matter of fact, you can directly set breakpoints atsource code lines using the command @code{sbp LINE_NO}, e.g.@exampleMIX > sbp 4Breakpoint set at line 7MIX > @end example@noindent@code{sbp} sets the breakpoint at the first meaningful source code line;thus, in the above example we have requested a breakpoint at a linewhich does not correspond to a MIX instruction and the breakpoint is setat the first line containing a real instruction after the given one. Tounset breakpoints, use @code{cbpa ADDRESS} and @code{cbp LINE_NO}, or@code{cabp} to remove all currently set breakpoints. You can also setconditional breakpoints, i.e., tell @code{mixvm} to interrupt programexecution whenever a register, a memory cell, the comparison flag or theoverflow toggle change using the commands @w{@code{sbp[rmco]}}(@pxref{Debug commands}).@cindex @code{psym}MIXAL lets you define symbolic constants, either using the @code{EQU}pseudoinstruction or starting an instruction line with a label (whichassigns to the label the value of the current memory address). EachMIXAL program has, therefore, an associated symbol table which you caninspect using the @code{psym} command. For our hello world sample, youwill obtain the following output:@exampleMIX > psymSTART: 3000TERM: 19MSG: 3002MIX > @end exampleOther useful commands for debugging are @code{strace} (which turns ontracing of executed intructions), @code{pbt} (which prints a backtraceof executed instructions) and @code{weval} (which evaluatesw-expressions on the fly). For a complete description of all availableMIX commands, @xref{mixvm}.@node Using mixguile, Using Scheme in mixvm and gmixvm, Running the program, Getting started@section Using @code{mixguile}With @code{mixguile} you can run a MIX simulator embedded in a Guileshell, that is, using Scheme functions and programs. As with@code{mixvm}, @code{mixguile} can be run both in interactive andnon-interactive modes. The following subsections provide a quick tour onusing this MIX emulator.@menu* The mixguile shell:: Using the Scheme MIX virtual machine.* Additional functions:: Scheme functions accessing the VM.* Defining new functions:: Defining your own Scheme functions.* Hook functions:: Using command and break hook functions.* Scheme scripts:: @end menu@node The mixguile shell, Additional functions, Using mixguile, Using mixguile@subsection The @code{mixguile} shell@cindex Scheme@cindex @code{mixguile}@cindex REPLIf you simply type@examplemixguile @key{RET}@end example@noindentat the command prompt, you'll be presented a Guile shell prompt likethis@exampleguile>@end example@noindentAt this point, you have entered a Scheme read-eval-print loop (REPL)which offers you all the Guile functionality plus a new set of built-inprocedures to execute and debug MIX programs. Each of the @code{mixvm}commands described in the previous sections (and in @pxref{mixvm}) havea Scheme function counterpart named after it by prepending the prefix@code{mix-} to its name. Thus, to load our hello world program, you cansimply enter@exampleguile> (mix-load "hello")Program loaded. Start address: 3000guile> @end example@noindentand run it using @code{mix-run}:@exampleguile> (mix-run)Running ...MIXAL HELLO WORLD ... doneElapsed time: 11 /Total program time: 11 (Total uptime: 11)guile> @end example@noindentIn the same way, you can execute it step by step using the Schemefunction @code{mix-next} or set a breakpoint:@exampleguile> (mix-sbp 4)Breakpoint set at line 5guile> @end example@noindentor, if you one to peek at a register contents:@exampleguile> (mix-preg 'A)rA: + 00 00 00 00 00 (0000000000)guile> @end exampleYou get the idea: you have at your disposal all the @code{mixvm} and@code{gmixvm} commands by means of @code{mix-} functions. But, in caseyou are wondering, this is only the beginning. You also have at yourdisposal a whole Scheme interpreter, and you can, for instance, definenew functions combining the @code{mix-} and all other Schemeprimitives. In the next sections, you'll find examples of how to takeadvantage of the Guile interpreter.@node Additional functions, Defining new functions, The mixguile shell, Using mixguile@subsection Additional MIX Scheme functionsThe @code{mix-} function counterparts of the @code{mixvm} commands don'treturn any value, and are evaluated only for their side-effects(possibly including informational messages to the standard output and/orerror stream). When writting your own Scheme functions to manipulate theMIX virtual machine within @code{mixguile} (@pxref{Defining newfunctions}), you'll probably need Scheme functions returning the valueof the registers, memory cells and so on. Don't worry: @code{mixguile}also offers you such functions. For instance, to access the (numerical)value of a register you can use @code{mix-reg}:@exampleguile> (mix-reg 'I2)0guile> @end example@noindentNote that, unlike @code{(mix-preg 'I2)}, the expression @code{(mix-reg'I2)} in the above example evaluates to a Scheme number and does notproduce any side-effect:@exampleguile> (number? (mix-reg 'I2))#tguile> (number? (mix-preg 'I2))rI2: + 00 00 (0000) #fguile> @end exampleIn a similar fashion, you can access the memory contents using@code{(mix-cell)}, or the program counter using @code{(mix-loc)}:@exampleguile> (mix-cell 3000)786957541guile> (mix-loc)3002guile> @end exampleOther functions returning the contents of the virtual machine componentsare @code{mix-cmp} and @code{mix-over}, which eval to the value of thecomparison flag and the overflow toggle respectively. For a completelist of these additional functions, @xref{mixguile}.In the next section, we'll see a sample of using these functions toextend @code{mixguile}'s functionality.@node Defining new functions, Hook functions, Additional functions, Using mixguile@subsection Defining new functions@cindex Scheme functionsScheme is a powerful language, and you can use it inside @code{mixguile}to easily extend the MIX interpreter's capabilities. For example, youcan easily define a function that loads a file, prints its name,executes it and, finally, shows the registers contents, all in one shot:@exampleguile> (define my-load-and-run @key{RET} (lambda (file) @key{RET} (mix-load file) @key{RET} (display "File loaded: ") @key{RET} (mix-pprog) @key{RET} (mix-run) @key{RET} (mix-preg))) @key{RET}guile> @end example@noindentand use it to run your programs:@exampleguile> (my-load-and-run "hello")Program loaded. Start address: 3000File loaded: hello.mixRunning ...MIXAL HELLO WORLD ... doneElapsed time: 11 /Total program time: 11 (Total uptime: 33)rA: + 00 00 00 00 00 (0000000000)rX: + 00 00 00 00 00 (0000000000)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) guile> @end exampleOr, maybe, you want a function which sets a breakpoint at a specifiedline number before executing it:@exampleguile> (define my-load-and-run-with-bp (lambda (file line) (mix-load file) (mix-sbp line) (mix-run)))guile> (my-load-and-run-with-bp "samples/primes" 10)Program loaded. Start address: 3000Breakpoint set at line 10Running ...... stopped: breakpoint at line 10 (address 3001)Elapsed time: 1 /Total program time: 1 (Total uptime: 45)guile>@end exampleAs a third example, the following function loads a program, runs it andprints the contents of the memory between the program's start and endaddresses:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -