home

Debugging ASM

Major Revision Sept 24, 2000 for new macro library

  Ever get the feeling writing asm programs is like typing on a keyboard in a small enclosed room at night while blindfolded? With gloves on? You write what you believe to be good code, get the compiler to finally accept it, hit the RUN button, and see...  nothing?  Or worse, a GPF?  You go back to your source code and look... it maybe this, it maybe that, but how to tell?

  Wouldn't it be nice if you could somehow make a window inside your program to see what is happening? Sure, there is soft ice. It's a find product, but not something I'm interested in using. I don't want to make major changes to my machine just to check some code. I use my computer for many things, some of them just running applications such as spread sheets or CAD programs, and I just don't want any extra overhead running. I want it as light and simple as I can get it.

  But still, how to get that window inside? Well, there are three simple ways this window could work. Here they are in increasing complexity:

  • message boxes - not bad for a few items, simple and direct, but each must be

  •                         dismissed. No good for say spying on the message loop.
     
  • a display window - pretty good, runs on the side of your program filling with 

  •                        information. Can even spy the message loop as items will scroll 
                           up and out of it.
     
  • text files - good for lots of information, gives you a static view of what your

  •                        program did. Must be opened to be viewed.
  Towards this end I wrote the Dmacros.inc file. It is a series of useful functions to print comments, values, strings, just enough to give you that window inside your work. It's just powerful enough that for simple programs (the kind of scribble you write for yourself on the side to work out some concept) it may well be all you need for your GUI.

  Let me digress a bit first about the display window used. It's just a standard console window, the good old DOS box. It can be a very powereful tool.  You can have any windows program open a console by invoking "AllocConsole" to see the messages.But even better is to start your program from a console (even a windows program). Your program will send its messages to this box, and if you start the program with a pipe then the pipe file gets the messages. 

  IE, start myprogram.exe like this:  "myprogram.exe >myprogram.txt"  and you will get a file of the messages in myprogram.txt.  Clean and simple.

  Here is a list of the debug macro commands inside Dmacros.inc:

 DPrint TO CONSOLE OR MESSAGEBOX:

 The DPrint macros will direct debug information to either
 a message box (only good for a few messages) or to a console
 output (even better: show you the program's dynamic action 
 as it happens.

 Define one of the following BEFORE the include files area:

     DEBUGC  EQU 1       ; console debug print

     DEBUGW  EQU 1       ; windows debug print
 

 DPrint Debug statements may be added as follows:
 

     DPrint "Message here"       ; print a comment

     DPrintValD eax, "EAX"       ; print a comment followed by 
                                 ;  a register value (in decimal)

     DPrintValH eax, "EAX"       ; print a comment followed by 
                                 ;  a register value (in hex)

     DPrintSZ OFFSET szString , "The string is"
                                 ; print a zero terminated string
                                 ;  note uses a pointer
                                 ;  also note also prints a comment string

   To use console output, use the Console build options of Quick Editor
 This is completely compatable with a windows app, as you will get both
 the application window, and a console.

   If the console app is started from a dos box, the console output 
 goes there. This output may then be piped to a file.

   IE,
      c:\somepath>MyApp.exe  >MyApp.txt

 This command dumps the console output to the file MyApp.txt

 When using the windows app option, message boxes will appear. This
 is only desirable for a very few messages. NOT SUITABLE for 
 monitoring the message loop for sure.

 Also note, these functions will work quite happily on displaying 
 value in memory, so that this is quite legal:

     DPrintValH SomeVar, "SomeVar is" ; print a comment followed by 
                                      ;  a memory variable value (in hex)
 
 

 LOGGING TO FILES:

 The Dlog series of macros perform the same actions as the DPrint series,
 but send their output to a text file. 

 Dlog differs in that the file must be opened and closed, and appropiate
 macros for this are included
 

 DLog Debug statements may be added as follows:
 

Define the following BEFORE the include files area:

    DEBUGL  EQU 1       ; console debug print
 

    DLogStart "MyApp.txt"     ; opens the file for information
                              ;  this exampl names the file 
                              ;  "MyApp.txt"
                              ;  MUST be performed before any 
                              ;  other DLog statement

    DLogEnd                   ; Closes the file, place just before your 
                              ;  your app terminates. The file will
                              ;  be closed by the OS if your program
                              ;  crashes before normal termination.

    DLog "Message here"       ; print a comment
    DLogValD eax, "EAX"       ; print a comment followed by 
                              ;  a register value (in decimal)

    DLogValH eax, "EAX"       ; print a comment followed by 
                              ;  a register value (in hex)

    DLogSZ OFFSET szString , "The string is"
                              ; print a zero terminated string
                              ;  note uses a pointer
                              ;  also note also prints a comment string
 

  One final warning. These macros depend on the (at this time) unreleased  next version of the masm32 library. Presently, the lib has no DWORD to HEX function, so I wrote one. Hutch says he will add it next release. For now, you will have to add this module yourself with these files.

Get Dmacros.zip here

home