home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / gwbasic / com2asm / com2asm.bas next >
Encoding:
BASIC Source File  |  1994-05-25  |  3.5 KB  |  77 lines

  1. 1000 ' COM2ASM.BAS Ver 1.1, by Richard Winkel
  2. 1010 ' This program may not be compiled because of
  3. 1020 ' some unresolved FOR/NEXT-statements
  4. 1030 ' For free distribution only; not for sale
  5. 1040 DEFINT A-Z
  6. 1050 DIM LIN$(999), JMP$(25) ' referenced addresses, jump instructions
  7. 1060 GOSUB 1670
  8. 1070 INPUT "Enter name of input file: ", INFILE$
  9. 1080 INPUT "Enter name of output file: ", OUTFILE$
  10. 1090 OPEN INFILE$ FOR INPUT AS #1
  11. 1100 OPEN OUTFILE$ FOR OUTPUT AS #2: PRINT #2, ".RADIX 16"
  12. 1110 IF EOF(1) THEN 1200
  13. 1120 LINE INPUT #1, A$
  14. 1130 IF LEN(A$) < 28 THEN 1110 ELSE J$ = MID$(A$, 25, 4)
  15. 1140 FOR I = 1 TO JMPNUM
  16. 1150   IF J$ <> JMP$(I) THEN GOSUB 1720: GOTO 1110
  17. 1160   IF MID$(A$, 33, 1) = "[" THEN GOTO 1110 ' if indirect addressing, skip it
  18. 1170   IF MID$(A$, 33, 3) = "FAR" THEN GOTO 1110
  19. 1180   IF MID$(A$, 37, 1) = ":" THEN GOTO 1110 'if inter-segment jump, skip
  20. 1190   LIN = LIN + 1: LIN$(LIN) = MID$(A$, 33, 4): GOTO 1110'otherwise, save the reference
  21. 1200   CLOSE #1
  22. 1210   OPEN INFILE$ FOR INPUT AS #1 're-position read pointer
  23. 1220   PRINT "Sorting..."  ' super shell sort (Byte, May '83)
  24. 1230   D = 2 ^ INT(LOG(LIN) / LOG(2)) - 1 ' sort referenced addresses
  25. 1240   FOR I = 1 TO LIN - D
  26. 1250     IF LIN$(I) <= LIN$(I + D) THEN 1310 ELSE T$ = LIN$(I + D): LIN$(I + D) = LIN$(I)
  27. 1260     IF I <= D THEN LIN$(I) = T$: GOTO 1310
  28. 1270     FOR J = I - D TO 1 STEP -D
  29. 1280       IF T$ >= LIN$(J) THEN 1300 ELSE LIN$(J + D) = LIN$(J)
  30. 1290     NEXT J
  31. 1300     LIN$(J + D) = T$
  32. 1310   NEXT I
  33. 1320   D = INT(D / 2): IF D > 0 THEN GOTO 1240 ELSE I = 1
  34. 1330   IF I = LIN THEN 1370 ' array is sorted, now get rid of duplicates
  35. 1340     IF LIN$(I) = LIN$(I + 1) THEN FOR J = I TO LIN: LIN$(J) = LIN$(J + 1): NEXT: LIN = LIN - 1 ELSE I = I + 1
  36. 1350   GOTO 1330
  37. 1360 ' *****************************************************
  38. 1370 L = 1 ' now go back thru file and plug in labels for addresses
  39. 1380 IF NOT EOF(1) THEN 1420 ELSE IF L > LIN THEN 1400 ' else premature EOF
  40. 1390 PRINT "Error: Referenced code at "; LIN$(L); "was not found."
  41. 1400 CLOSE
  42. 1410 END
  43. 1420 LINE INPUT #1, A$: IF LEN(A$) < 28 THEN 1380
  44. 1430 IF MID$(A$, 6, 4) < LIN$(L) THEN MID$(A$, 6, 4) = " ": GOTO 1480'not referenced
  45. 1440 IF MID$(A$, 6, 4) = LIN$(L) THEN 1460'plug in label
  46. 1450 IF L > LIN THEN MID$(A$, 6, 4) = " ": GOTO 1480 ELSE 1390'err: skipped over code
  47. 1460 L$ = STR$(L): L$ = "L" + RIGHT$(L$, LEN(L$) - 1)
  48. 1470 L$ = L$ + ":" + STRING$(4 - LEN(L$), " "): MID$(A$, 6, 5) = L$: L = L + 1
  49. 1480 J$ = MID$(A$, 25, 4)
  50. 1490 FOR I = 1 TO JMPNUM
  51. 1500   IF J$ <> JMP$(I) THEN GOSUB 1720: GOTO 1600
  52. 1510   IF MID$(A$, 33, 1) = "[" THEN 1600
  53. 1520   IF MID$(A$, 33, 3) = "FAR" THEN 1600
  54. 1530   IF MID$(A$, 37, 1) = ":" THEN 1600
  55. 1540   REF$ = MID$(A$, 33, 4)
  56. 1550   FOR I = 1 TO LIN
  57. 1560     IF REF$ <> LIN$(I) THEN GOSUB 1720
  58. 1570     L$ = STR$(I)
  59. 1580     L$ = "L" + RIGHT$(L$, LEN(L$) - 1) ' replace destination addr with label
  60. 1590     MID$(A$, 33, 4) = L$ + STRING$(4 - LEN(L$), " ")
  61. 1600     A$ = MID$(A$, 6, 5) + " " + RIGHT$(A$, LEN(A$) - 23) ' get rid of set & opcode
  62. 1610     FOR I = LEN(A$) TO 2 STEP -1
  63. 1620       IF MID$(A$, I, 1) = " " THEN GOSUB 1720
  64. 1630       A$ = LEFT$(A$, I) ' chop of trailing blanks
  65. 1640       PRINT A$: PRINT #2, A$
  66. 1650 GOTO 1380
  67. 1660 ' *******************
  68. 1670 JMPNUM = 20
  69. 1680 FOR I = 1 TO JMPNUM
  70. 1690   READ JMP$(I)
  71. 1700   NEXT
  72. 1710 RETURN
  73. 1720 NEXT
  74. 1730 RETURN
  75. 1740 DATA "JMP ","JZ  ","JNZ ","LOOP","CALL","JCXZ","JB  ","JBE ","JNB ","JA  "
  76. 1750 DATA "JG  ","JGE ","JL  ","JLE ","JNO ","JPO ","JNS ","JO  ","JPE ","JS  "
  77.