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

📄 mdk_mixguile.texi

📁 汇编语言编程源代码
💻 TEXI
字号:
@c -*-texinfo-*-@c This is part of the GNU MDK Reference Manual.@c Copyright (C) 2000, 2001@c   Free Software Foundation, Inc.@c See the file mdk.texi for copying conditions.@c $Id: mdk_mixguile.texi,v 1.3 2001/09/28 23:11:44 jao Exp $@node mixguile, Problems, gmixvm, Top@chapter @code{mixguile}, the Scheme virtual machine@cindex @code{mixguile}This chapter provides a reference to using @code{mixguile} and theScheme function library giving access to the MIX virtual machine in the@sc{mdk} emulators (@code{mixguile}, @code{mixvm} and @code{gmixvm}). See@ref{Using mixguile} for a tutorial, step by step introduction to@code{mixguile} and using Scheme as an extension language for the@sc{mdk} MIX virtual machines.@menu* Invoking mixguile::           Command line options.* Scheme functions reference::  Scheme functions accessing the VM.@end menu@node Invoking mixguile, Scheme functions reference, mixguile, mixguile@section Invoking @code{mixguile}@cindex @code{mixguile} optionsInvoking @code{mixguile} without arguments will enter the Guile REPL(read-eval-print loop) after loading, if it exists, the user'sinitialisation file (@file{~/.mdk/mixguile.scm}).@code{mixguile} accepts the same command line options than Guile:@examplemixguile [-s SCRIPT] [-c EXPR] [-l FILE] [-e FUNCTION] [-qhv]         [--help] [--version]@end exampleThe meaning of these options is as follows:@defopt -h@defoptx --helpPrints usage summary and exits.@end defopt@defopt -v@defoptx --versionPrints version and copyleft information and exits.@end defopt@defopt -s SCRIPTLoads Scheme code from @var{script}, evaluates it and exits. This optioncan be used to write executable Scheme scripts, as described in@ref{Scheme scripts}.@end defopt@defopt -c EXPREvaluates the given Scheme expression and exits.@end defopt@defopt -l FILELoads the given Scheme file and enters the REPL (read-eval-print loop).@end defopt@defopt -e FUNCTIONAfter reading the script, executes the given function using the providedcommand line arguments. For instance, you can write the following Schemescript:@example#! /usr/bin/mixguile \-e main -s!#;;; execute a given program and print the registers.(define main  (lambda (args)    ;; load the file provided as a command line argument    (mix-load (cadr args))    ;; execute it    (mix-run)    ;; print the contents of registers    (mix-pall)))@end example@noindentsave it in a file called, say, @file{foo}, make it executable, and runit as@example$ ./foo hello@end example@noindentThis invocation will cause the evaluation of the @code{main} functionwith a list of command line parameters as its argument (@code{("./foo""hello")} in the above example. Note that command line options tomixguile must be written in their own line after the @code{\} symbol.@end defopt@defopt -qDo not load user's initialisation file. When @code{mixguile} starts up,it looks for a file named @file{mixguile.scm} in the user's @sc{mdk}configuration directory (@file{~/.mdk}), and loads it if it exists. Thisoption tells @code{mixguile} to skip this initialisation file loading.@end defopt@node Scheme functions reference,  , Invoking mixguile, mixguile@section Scheme functions referenceAs we have previously pointed out, @code{mixguile} embeds a MIX virtualmachine that can be accessed through a set of Scheme functions, that is,of a Scheme library. Conversely, @code{mixvm} and @code{gmixvm} containa Guile interpreter, and are able to use this same Scheme library, aswell as all the other Guile/Scheme primitives and any user definedfunction. Therefore, you have at your disposal a powerful programminglanguage, Scheme, to extend the @sc{mdk} virtual machine emulators (see@ref{Using Scheme in mixvm and gmixvm} for samples of how to do it).The following subsections describe available functions the MIX/Schemelibrary.@menu* mixvm wrappers::              Functions invoking mixvm commands.* Hooks::                       Adding hooks to mixvm commands.* Additional VM functions::     Functions accessing the MIX virtual machine.@end menu@node mixvm wrappers, Hooks, Scheme functions reference, Scheme functions reference@subsection @code{mixvm} command wrappersFor each of the @code{mixvm} commands listed in @ref{Commands}, there isa corresponding Scheme function named by prefixing the command name with@code{mix-} (e.g., @code{mix-load}, @code{mix-run} and so on). Thesecommand wrappers are implemented using a generic command dispatchingfunction:@defun mixvm-cmd command argumentDispatchs the given @var{command} to the MIX virtual appending theprovided @var{argument}. Both @var{command} and @code{argument} must bestrings. The net result is as writing "@var{command} @var{argument}" atthe @code{mixvm} or @code{gmixvm} command prompt.@end defunFor instance, you can invoke the @code{run} command at the @code{mixvm}prompt in three equivalent ways:@exampleMIX > run helloMIX > (mix-run "hello")MIX > (mixvm-cmd "run" "hello")@end example@noindent(only the two last forms can be used at the @code{mixguile} prompt orinside a Scheme script).The @code{mix-} functions evaluate to a unspecified value. If you wantto check the result of the last @code{mixvm} command invocation, use the@code{mix-last-result} function:@defun mix-last-resultReturns @var{#t} if the last @code{mixvm} command invocation wassuccessful, @var{#f} otherwise.@end defun@noindentUsing this function, we could improve the script for running a programpresented in the previous section by adding error checking:@example#! /usr/bin/mixguile \-e main -s!#;;; Execute a given program and print the registers.(define main  (lambda (args)    ;; load the file provided as a command line argument    (mix-load (cadr args))    ;; execute it if mix-load succeeded    (if (mix-last-result) (mix-run))    ;; print the contents of registers if the above commands succeded    (if (mix-last-result) (mix-pall))))@end examplePlease, refer to @ref{Commands} for a list of available commands. Giventhe description of a @code{mixvm}, it is straightforward to use itsScheme counterpart and, therefore, we shall not give a completedescription of these functions here. Instead, we will only mention thosewrappers that exhibit a treatment of their differing from that of theircommand counterpart.@defun mix-preg [register]@defunx mix-sreg register valueThe argument @var{register} of these functions can be either a string ora symbol representing the desired register. For instance, the followinginvocations are equivalent:@example(mix-preg 'I1)(mix-preg "I1")@end example@end defun@defun mix-pmem from [to]The command @code{pmem} takes a single argument which can be either acell number or a range of the form @code{FROM-TO}. This function takesone argument to ask for a single memory cell contents, or two parametersto ask for a range. For instance, the following commands are equivalent:@exampleMIX > pmem 10-120010: + 00 00 00 00 00 (0000000000)0011: + 00 00 00 00 00 (0000000000)0012: + 00 00 00 00 00 (0000000000)MIX > (mix-pmem 10 12)0010: + 00 00 00 00 00 (0000000000)0011: + 00 00 00 00 00 (0000000000)0012: + 00 00 00 00 00 (0000000000)MIX >@end example@end defun@defun mix-sover #t|#fThe command @code{sover} takes as argument either the string @code{T} orthe string @code{F}, to set, respectively, the overflow toggle to trueor false. Its Scheme counterpart, @code{mix-sover}, takes as argumenta Scheme boolean value: @code{#t} (true) or @code{#f}.@end defunFor the remaining functions, you simply must take into account that whenthe command arguments are numerical, the corresponding Scheme functiontakes as arguments Scheme number literals. On the other hand, when thecommand argument is a string, the argument of its associated Schemefunction will be a Scheme string. By way of example, the followinginvocations are pairwise equivalent:@exampleMIX > load ../samples/helloMIX > (mix-load "../samples/hello)MIX > next 5MIX > (mix-next 5)@end example@node Hooks, Additional VM functions, mixvm wrappers, Scheme functions reference@subsection Hook functionsHooks are functions evaluated before or after executing a @code{mixvm}command (or its corresponding Scheme function wrapper), or after anexplicit or conditional breakpoint is found during the execution of aMIX program. The following functions let you install hooks:@defun mix-add-pre-hook command hookAdds a function to the list of pre-hooks associated with the give@var{command}. @var{command} is a string naming the corresponding @code{mixvm}command, and @var{hook} is a function which takes a single argument: astring list of the commands arguments. The following scheme code definesa simple hook and associates it with the @code{run} command:@example(define run-hook  (lambda (args)    (display "argument list: ")    (display args)    (newline)))(mix-add-pre-hook "run" run-hook)@end examplePre-hooks are executed, in the order they are added, before invoking thecorresponding command (or its associated Scheme wrapper function).@end defun@defun mix-add-post-hook command hookAdds a function to the list of pre-hooks associated with the give@var{command}. The arguments have the same meaning as in@code{mix-add-pre-hook}.@end defun@defun mix-add-global-pre-hook hook@defunx mix-add-global-post-hook hookGlobal pre/post hooks are executed before/after any @code{mixvm} commandor function wrapper invocation. In this case, @var{hook} takes twoarguments: a string with the name of the command being invoked, and astring list with its arguments.@end defun@defun mix-add-break-hook hook@defunx mix-add-cond-break hookAdd a hook funtion to be executed when an explicit (resp. conditional)breakpoint is encountered during program execution. @var{hook} is afunction taking two arguments: the source line number where the hook hasoccurred, and the current program counter value. The following codeshows a simple definition and installation of a break hook:@example(define break-hook  (lambda (line address)    (display "Breakpoint at line ") (display line)    (display " and address ") (display address)    (newline)))(mix-add-break-hook break-hook)@end exampleBreak hook functions are entirely implemented in Scheme using regularpost-hooks for the @code{next} and @code{run} commands. If you arecurious, you can check the Scheme source code at@file{@emph{prefix}/share/mdk/mixguile-vm-stat.scm} (where @emph{prefix}stands for your root install directory, usualy @code{/usr} or@code{/usr/local}. @end defunSee @ref{Hook functions} for further examples on using hook functions.@node Additional VM functions,  , Hooks, Scheme functions reference@subsection Additional VM functionsWhen writing non-trivial Scheme extensions using the MIX/Scheme library,you will probably need to evaluate the contents of the virtual machinecomponents (registers, memory cells and so on). For instance, you mayneed to store the contents of the @code{A} register in a variable. TheScheme functions described so far are of no help: you can print thecontents of @code{A} using @code{(mix-preg 'A)}, but you cannot define avariable containing the contents of @code{A}. To address this kind ofproblems, the MIX/Scheme library provides the following additionalfunctions: @defun mixvm-status@defunx mix-vm-statusReturn the current status of the virtual machine, as a number(@code{mixvm-status}) or as a symbol (@code{mix-vm-status}). Posiblereturn values are:@multitable {aamixvmaastatusaa} {aamixvmastatusaaaaaaa} {return valuesaaaaaaaaaaaaaaaaaaaaaaaaaa}@item @code{(mixvm-status)} @tab @code{(mix-vm-status)} @tab@item 0 @tab MIX_ERROR @tab Loading or execution error@item 1 @tab MIX_BREAK @tab Breakpoint encountered@item 2 @tab MIX_COND_BREAK @tab Conditional breakpoint@item 3 @tab MIX_HALTED @tab Execution terminated@item 4 @tab MIX_RUNNING @tab Execution stopped after @code{next}@item 5 @tab MIX_LOADED @tab Program successfully loaded@item 6 @tab MIX_EMPTY @tab No program loaded@end multitable@end defun@defun mix-vm-error?@defunx mix-vm-break?@defunx mix-vm-cond-break?@defunx mix-vm-halted?@defunx mix-vm-running?@defunx mix-vm-loaded?@defunx mix-vm-empty?Predicates asking whether the current virtual machine status is@code{MIX_ERROR}, @code{MIX_BREAK}, etc.@end defun@defun mix-reg register@defunx mix-set-reg! register value@code{mix-reg} evaluates to a number which is the contents of thespecified @var{register}. @code{mix-set-reg} sets the contents of thegiven @var{register} to @var{value}. The register can be specifiedeither as a string (@code{"A"}, @code{"X"}, etc.) or as a symbol(@code{'A}, @code{'X}, etc.). For instance,@exampleguile> (mix-reg 'A)2341guile> (mix-set-reg! "A" 2000)okguile> (define reg-a (mix-reg 'A))guile> (display reg-a)2000guile> @end example@end defun@defun mix-cell cell_no@defunx mix-set-cell! cell_no valueEvaluate and set the contents of the memory cell number@var{cell_no}. Both @var{cell_no} and @var{value} are Scheme numbers.@end defun@defun mix-locEvaluates to the value of the location counter (i.e., the address of thenext instruction to be executed).@end defun@defun mix-over@defunx mix-set-over! #t|#f@code{mix-over} evaluates to @code{#t} if the overflow toggle is set,and to @code{#f} otherwise. The value of the overflow toggle can bemodified using @code{mix-set-over!}.@end defun@defun mix-cmp@defunx mix-set-cmp! 'L|'E|'GEvaluate and set the comparison flag. Possible values are the schemesymbols @code{L} (lesser), @code{E} (equal) and @code{G} (greater).@end defun@defun mix-up-timeEvaluates to the current virtual machine uptime.@end defun@defun mix-lap-timeEvaluates to the current virtual machine lapsed time, i.e., the timeelapsed since the last @code{run} or @code{next} command.@end defun@defun mix-prog-timeEvaluates to the total time spent executing the currently loaded program.@end defun@defun mix-prog-nameEvaluates to a string containing the basename (without any leading path)of the currently loaded MIX program.@end defun@defun mix-prog-pathEvaluates to a string containing the full path to the currently loadedMIX program.@end defun@defun mix-src-pathEvaluates to a string containing the full path to the source file of thecurrently loaded MIX program.@end defun@defun mix-src-line [lineno]@defunx mix-src-line-no@code{mix-src-line-no} evaluates to the current source file numberduring the execution of a program.  @code{mix-src-line} evaluates to astring containing the source file line number @var{lineno}; wheninvoked without argument, it evaluates to @code{(mix-src-line(mix-src-line-no))}.@end defun@defun mix-ddirEvaluates to a string containing the full path of the current devicedirectory.@end defun

⌨️ 快捷键说明

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