'=========================================================================== ' Subject: DEBUG COMPILER UTILITY Date: 11-13-97 (21:00) ' Author: Bert van Dam Code: QB, QBasic, PDS ' Origin: bd1rsd@usa.net Packet: ASMCODE.ABC '=========================================================================== 'COMPILER.BAS : Debug compiler utility ' Bert van Dam, 1997. ' ' '---===[ LEGAL STUFF ' 'This source is donated to the public domain. It has been tested on a '486DX4/100 with 8Mb memory, QB4.5, QBasic and DEBUG. The program is 'provided as is, and I accept no resposibility whatsoever for any negative 'effects running this program might have. If you do not agree with this 'you may not use the program. Apart from that you can do anything you 'want with it. ' '---===[ PURPOSE: ' 'The purpose of this program is to allow programmers who don't own a real 'assembler compiler to write a source file and then turn it into a .COM 'file without the hassle of messing with program length, typing erors etc. ' '---===[ MANUAL: ' 'Write the assembler source in an appropriate editor and save in ascii. Do 'rembember to end the program with INT 20 otherwise you'll never get back 'to dos (and the compiler won't work). If you want to add comments they 'have to be on a separate line and start with a semi colon ; Save the file 'as HEX.ASM Now start the compiler. It will take the source code and turn 'it into a script file. It will then start DEBUG to determine the number 'of bytes (this is required since you need to tell debug how many bytes need 'to be saved to disk). After counting the bytes the script file will be 'modified to allow DEBUG to write to disk, and debug will be started again. 'The resulting file will be called HEX.COM in the currect directory. Use 'REN HEX.* YOURNAME.* to rename all files to something meaningful. ' ' '---===[ ALL'S NOT WELL ' 'The scripting results of the second script will be shown on-screen so 'you can see any errors you might have. Change HEX.ASM to correct these 'and run the compiler again. ' '---===[ SAMPLE FILE: HEX.ASM the original source (you write this) ' ';HEX.ASM ' ';test assembler source, makes a .com file that writes an ';asterix to the screen ' 'mov ah,02 'mov dl,2A 'int 21 'int 20 ' ' '---===[ SAMPLE FILE: HEX.SCR the final script file made by the compiler ' 'a 100 'mov ah,02 'mov dl,2A 'int 21 'int 20 ' 'n hex.com 'r bx '0 'r cx '8 'w 'q ' ' '---===[ SAMPLE FILE: HEX.PRN internal usage, you won't need this ' '-a 100 ' '5422:0100 mov ah,02 ' '5422:0102 mov dl,2A ' '5422:0104 int 21 ' '5422:0106 int 20 ' '5422:0108 ' '-u 100 ' '5422:0100 B402 MOV AH,02 '5422:0102 B22A MOV DL,2A '5422:0104 CD21 INT 21 '5422:0106 CD20 INT 20 '5422:0108 61 DB 61 '5422:0109 031F ADD BX,[BX] '5422:010B 8BC3 MOV AX,BX '5422:010D 48 DEC AX '5422:010E 12B1048B ADC DH,[BX+DI+8B04] '5422:0112 C6F70A MOV BH,0A '5422:0115 0AD0 OR DL,AL '5422:0117 D348DA ROR WORD PTR [BX+SI-26],CL '5422:011A 2BD0 SUB DX,AX '5422:011C 3400 XOR AL,00 '5422:011E 115400 ADC [SI+00],DX '-q ' ' ' ' 'COMPILER.BAS october 1997 CLS PRINT " ---===[Debug compiler utility]===---" PRINT " Bert van Dam" PRINT 'read assembler source and turn it into a script file and write to disk OPEN "hex.asm" FOR INPUT AS #1 OPEN "hex.scr" FOR OUTPUT AS #2 PRINT #2, "a 100" DO UNTIL EOF(1) LINE INPUT #1, Regel$ Regel$ = LTRIM$(RTRIM$(Regel$)) IF LEN(Regel$) > 0 THEN IF INSTR(Regel$, ";") = 0 THEN PRINT #2, Regel$ END IF END IF LOOP CLOSE #1 PRINT #2, "" PRINT #2, "u 100" PRINT #2, "q" CLOSE #2 'run debug with script file and save results in a capture file SHELL "debug < hex.scr > hex.prn" 'read the captured file in order to count bytes Program$ = "" OPEN "hex.prn" FOR INPUT AS #1 DO LINE INPUT #1, Regel$ LOOP WHILE INSTR(Regel$, "-u") = 0 LINE INPUT #1, Regel$ DO LINE INPUT #1, Regel$ Program$ = Program$ + " " + LTRIM$(RTRIM$(MID$(Regel$, 11, 2) +_ " " + MID$(Regel$, 13, 2) + " " + MID$(Regel$, 15, 2))) LOOP UNTIL EOF(1) OR INSTR(Regel$, "CD20") <> 0 CLOSE #1 IF INSTR(Regel$, "CD20") = 0 THEN PRINT "Unexpected end of file, program aborted." END END IF ProgramLength = LEN(Program$) / 3 'this time repeat the procedure but write compiled file to disk OPEN "hex.asm" FOR INPUT AS #1 OPEN "hex.scr" FOR OUTPUT AS #2 PRINT #2, "a 100" DO UNTIL EOF(1) LINE INPUT #1, Regel$ Regel$ = LTRIM$(RTRIM$(Regel$)) IF LEN(Regel$) > 0 THEN IF INSTR(Regel$, ";") = 0 THEN PRINT #2, Regel$ END IF END IF LOOP CLOSE #1 PRINT #2, "" PRINT #2, "n hex.com" PRINT #2, "r bx" PRINT #2, "0" PRINT #2, "r cx" PRINT #2, HEX$(ProgramLength) PRINT #2, "w" PRINT #2, "q" CLOSE #2 'run debug with script file, show results on-screen SHELL "debug < hex.scr" PRINT "You may now run HEX.COM to test it...." END