• Please review our updated Terms and Rules here

Boss, DEBUG! DEBUG!

neilobremski

Experienced Member
Joined
Oct 9, 2016
Messages
55
Location
Seattle, USA
The last few days I have been working my way through Jeff Duntemann's book, Assembly Language Step-By-Step (ISBN 978-0471578147), and my favorite part has been a gentle introduction into the DOS command DEBUG. My penchant for doing things the hard way has been particularly tickled by the ability to write assembler instructions in this old DOS utility.

Today I decided to see if I could combine what I have learned with what I already know about the CGA and BIOS routines by writing MAGENTA.COM which does the following:

  1. Get the current screen mode (INT 10h, AH=0F)
  2. Change to CGA mode 4 (320x200)
  3. Fill the video buffer with bits for the color magenta
  4. Wait for a key press (INT 16h, AH=00)
  5. Change the screen back to its original mode
  6. Exit to DOS gracefully (INT 21h, AH=4C)

Here is the machine code I generated:

Code:
0964:0100  EB 0E 03 50 6A 24 00 00-00 00 00 00 00 00 00 00   k..Pj$..........
0964:0110  31 C0 B4 0F CD 10 A3 02-01 30 E4 B0 04 CD 10 B8   1@4.M.#..0d0.M.8
0964:0120  00 B8 8E C0 31 FF B8 AA-AA B9 00 20 F3 AB 30 E4   .8.@1.8**9. s+0d
0964:0130  CD 16 A3 04 01 A1 02 01-30 E4 CD 10 B0 00 B4 4C   M.#..!..0dM.0.4L
0964:0140  CD 21 00 00 00 00 00 00-00 00 00 00 00 00 00 00   M!..............

And here is the disassembly of that ...

Code:
0964:0100 EB0E          JMP     0110                               
...
0964:0110 31C0          XOR     AX,AX                              
0964:0112 B40F          MOV     AH,0F                              
0964:0114 CD10          INT     10                                 
0964:0116 A30201        MOV     [0102],AX                          
0964:0119 30E4          XOR     AH,AH                              
0964:011B B004          MOV     AL,04                              
0964:011D CD10          INT     10                                 
0964:011F B800B8        MOV     AX,B800                            
0964:0122 8EC0          MOV     ES,AX                              
0964:0124 31FF          XOR     DI,DI                              
0964:0126 B8AAAA        MOV     AX,AAAA                            
0964:0129 B90020        MOV     CX,2000                            
0964:012C F3            REPZ                                       
0964:012D AB            STOSW                                      
0964:012E 30E4          XOR     AH,AH                              
0964:0130 CD16          INT     16                                 
0964:0132 A30401        MOV     [0104],AX                          
0964:0135 A10201        MOV     AX,[0102]                          
0964:0138 30E4          XOR     AH,AH                              
0964:013A CD10          INT     10                                 
0964:013C B000          MOV     AL,00                              
0964:013E B44C          MOV     AH,4C                              
0964:013C B000          MOV     AL,00                              
0964:013E B44C          MOV     AH,4C                              
0964:0140 CD21          INT     21

I use the first 16 bytes for data but jumping over it eats away 2 leaving only 14. That's still overkill, though, because even though this stores the results of the keystroke and the old screen mode, it really only needs 1 byte total for the latter. I punched all this in on my Tandy 1000 HX and it worked wonderfully.

Afterwards, in order to get the above listings, I created a "DEBUG script" like so:

Code:
> echo d > script.txt
> echo u >> script.txt
> echo q >> script.txt
> debug magenta.com < script.txt > magenta.txt

I could have probably edited the script text using DEBUG itself but somehow it was more satisfying to pipe it around a bit.

P.S. -- Daniel B. Sedory's A Guide to DEBUG is probably the best help you can find on this utility and is deservedly high in search engines.
 
Back
Top