A Quick Tutorial
This is deliberately a 'quick and dirty' tutorial so you can see how straightforward it is to create, edit, assemble and debug programs with Devpac.
In this tutorial we are going to assemble and run a simple program, which contains two errors and debug it. The program itself is intended to print a message.
To follow this tutorial you must already have installed Devpac and be in the editor. If you are not you should run the installation program (assuming you have not already done so), then double-click on the DEVPAC.PRG icon from your work disk.
You will then be presented with an empty window; to load the file you should move the mouse over the File menu and click on Load.... The standard GEM file selector will then appear and the file we want is called DEMO.S. You may either double-click on the name or type it in and press Return to load the file. Note that the file is in the EXAMPLES directory on your work disk.
When the file has loaded the window will show the top lines of the file. If you want to have a quick look at the program you may click on the scroll bar or use the cursor keys.
With most shorter programs it is best to have a trial assembly that doesn't produce a listing or binary file to check the syntax of the source and show up typing errors and so on. Move the mouse to the Program menu and select Check.
The assembler will report an error, instruction not recognised, pressing any key will return you to the editor. The cursor will be placed on the incorrect line and the error message displayed in the window title bar.
The program line should be changed from MOV. L to MOVE . L, so do this, then select Control... from the Options menu and change the setting of the Format popup menu to ST RAM. This is very much faster than assembling to disk and allows you to try things out immediately, which is exactly what we want.
If you are unsure of how any of the user interface elements work, you may like to read the section A word about pop-up menus and dialogs now.
The assembly worked this time, so click on Run from the Program menu, and what happens? Not a lot it would seem, except that some bombs appeared briefly on the screen - oh, there's a bug.
Some alternate desktops (e.g. NeoDeskā¢) and other programs (e.g. MiNT) replace the standard bomb handler; in this case you won't see bombs, but that program's 'bomb' handlers message...
The tool for finding bugs and checking programs is a debugger, so select Debug from the Program menu which will call the debugger. This is described more fully later, but for now we just want to run the program from the debugger to 'catch' any problems and find out what causes them, so press Control-R to run the program.
On a 68000 computer, the message Address Error will appear at the bottom of the display, with the Disassembly window showing the current instruction
This instruction causes an address error on a 68000 because the location 1 is at an odd address which cannot be accessed with the MOVE. W instruction.
This is not the case on 68020s upwards and, you will instead see the message Bus Error, but with the Disassembly window showing the same instruction. In this instance the problem is because location 1 is in protected memory which cannot be accessed in user mode.

However, for all processors, the problem is the same - there should a hash sign before the 1 to put the immediate value of 1 on the stack. To return to the editor press Control-C twice (once to terminate your program, once to terminate the debugger), so we can fix this bug in the source code.
Press Alt-T, to go to the top of the file, then click on Find from the Search menu. We are going to find the errant instruction so enter:
move.w then press Return to start.the search. The first occurrence has a hash sign, so press Alt-N to find the next, which is the line:
Ahah! - this is the one, so add a hash to change it to move.w #c_conin,-(a7)
then assemble it again. If you click on Run from the Program menu you should see the message, and pressing any key will return you to the editor.
However, did you notice how messy the screen was - the desktop pattern looked very untidy and you possibly got mouse 'droppings' left on the screen. This was because DEMO is a TOS program running with a GEM screen - to change this, click on Run with GEM from the Program menu - the check mark next to it should disappear. If you select Run again you can see the display is a lot neater, isn't it? If you run a GEM program you must ensure the check mark is there beforehand, otherwise nasty things can happen.
Although the program now works we shall use Mon, the debugger, to trace through the program, step by step. To do this select Debug from the Program menu, the debugger will appear with the message Breakpoint, showing your program.
There are various windows, the top one displaying the machine registers, the second a disassembly of the program, and the third some other memory.
If you look at window 2, the Disassembly window, you will see the current instruction, which in this case is
As the debug option was specified in the source code all program symbols will appear in the debugger.
Let's check the area around string. Press Alt-3 and you should see window 3's title inverted. Next press Alt-A and a dialog box will appear, asking Window start address? - to this enter string and press Return. This will re-display window 3 at that address, showing the message in both hex and ASCII.
To execute this MOVE instruction press Control-Z. This will execute the instruction then the screen will be updated to reflect the new values of the program counter and register A7. If you press Control-Z again the MOVE . W instruction will be executed. If you look at the hex display next to A7 you should see a word of 9, which is what you would expect after that instruction.
The next instruction is TRAP #1, to call GEMDOS to print a string, but hang on - would we notice a string printed in the middle of the Mon display? Never fear, Mon has its own screen to avoid interference with your program's, to see this press the V key, which will show a blank screen, ready for your program. Pressing any other key will return you to Mon.
To execute this call press Control-Z, which will have printed the string. To prove it press V again, then any key to return to Mon.
Press Control-Z twice more until you reach the next trap. This one waits for a key press so hit Control-Z and the program display will automatically appear, waiting for a key. When you're ready, press the q key. You will return to Mon and if you look at the register window the low 8 bits of register DO should be $71, the ASCII code for q, and next to that it will be shown as q (unless in low-resolution).
The final trap quits the program, so to let it run its course press Control-R, you will then return to the debugger as the program has finished. Finally press Control-C to leave the debugger and return to the editor.
That completes our quick tutorial.
Responses
-
BId6 months ago
- Reply