home *** CD-ROM | disk | FTP | other *** search
-
- BASIC Function for Assembler Debug Facility
- ===========================================
- (directory AsmDebug)
-
- When writing and testing any program it is very useful to be able to follow
- the execution path through the program. This facility is provided in BASIC
- by the TRACE facility, which will display the statement number being
- executed. It is also easy in BASIC to insert extra PRINT statements so that
- the flow can be seen, and variables displayed.
-
- These problems exist also when writing assembler programs, with the added
- difficulty that assembler programs can easily loop or overwrite unintended
- bits of storage, often locking up the computer completely with no clues
- where it is. In assembler there is no TRACE facility, and although SWI
- calls can be inserted to display characters or strings, the insertion can
- cause the program to change its behaviour due to register corruption.
- Breakpoints can be inserted using *BreakSet, but these are limited, and slow
- the program down.
-
- My solution to this was to write a BASIC function which generates assembler
- code to enable trace entries to be easily inserted at any point in an
- assembler program. All that is needed is to insert FNdebug("message of your
- choice") : this will generate code to print the message from the parameter
- to identify the location, then provide a full register list, plus the flag
- values, and then return to the program under test, with all registers and
- flags unchanged. The debug functions can be left in the source, and turned
- on and off for any assembly simply by setting debug to TRUE or FALSE. The
- code will run in User mode, and also in Supervisor mode.
-
- There is obviously some storage overhead when running with debug, which is
- about 300 bytes for code which included only once, and 13 bytes plus the
- length of the message for each FNdebug included in the program. It also
- slows the code down, but you normally need to slow it down much further with
- CTRL+SHIFT to read the debug information!
-
- The debug function is fully documented, and it needs only 2 variables set
- before it can be used: opt should be set to the assembler OPT value, and
- debug should be set to TRUE to generate debug code, or FALSE to omit it.
- Note that there must also be included in the program FNdebug("Debug_Init")
- :this will generate the common code if debug is TRUE. It should be placed
- after the end of the executable code. After assembly CALL showregs can be
- used to obtain a register list at any time from BASIC.
-
- The sample program DemoDebug includes the function as a LIBRARY, then
- assembles a short routine either with or without the debug facility, then
- CALLs the routine. Run the program first to see what the assembler program
- does (don't get too exited!) then change line 40 to debug = TRUE and RUN the
- program again to see the debug function in action.
-
-
- Martin Avison