home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / PJGRAPH.ZIP / CHAP09.6 < prev    next >
Encoding:
Text File  |  1989-09-26  |  1.9 KB  |  58 lines

  1. ; Solution to MASM 5.0 problem with local labels in REPT blocks.
  2. ; Adrian Crum's solution.
  3. ;
  4. ; Note: this code is relatively simple, it should be easy to follow.
  5. ; Make sure that the counter, (?CNT1) is initialized only one in
  6. ; your program. Otherwise, you will receive multi-defined errors.
  7. ;
  8. DOSSEG
  9. .MODEL SMALL
  10. .CODE
  11. ;
  12. ;
  13. SYM_SUPP1       MACRO   X
  14.         ;; support macro #1 for SYMBOLS macro
  15.         ;;
  16.         jmp     ?TMPLBL&X&
  17.         ;;
  18.         ;; Note: if you're sure that these will always be short jumps,
  19.         ;; then JMP SHORT ?TMPLBL&X&
  20.         ;;
  21. ENDM
  22. SYM_SUPP2       MACRO   X
  23.         ;; Support macro #2 for SYMBOLS macro
  24.         ;;
  25.         ?TMPLBL&X&:
  26.         ;;
  27. ENDM
  28. ;
  29. SYMBOLS MACRO
  30.         ;; This is the main macro. No calling parameters. This macro
  31.         ;; calls two other macros to generate 10 JMP instructions to
  32.         ;; 10 temporary labels and the temporary labels themselves.
  33.         ;;
  34.         REPT    10
  35.                 SYM_SUPP1       %?CNT1  ;; Generate JMP instruction
  36.                 SYM_SUPP2       %?CNT1  ;; Generate label
  37.                 ?CNT1 = ?CNT1 + 1       ;; Increment counter
  38.         ENDM
  39.         ;;
  40.         ;; Note: you could also define the number of repeats executed
  41.         ;; by this macro by including a dummy parameter X at the
  42.         ;; beginning of the macro and changing REPT 10 to REPT &X. The
  43.         ;; correct call in that case would be SYMBOLS n, where n is
  44.         ;; the number of repetitions.
  45.         ;;
  46. ENDM
  47. ;
  48. START:
  49.         ?CNT1 = 0                       ; INITIALIZE COUNTER
  50.         SYMBOLS                         ; GENERATE 10 TEMP LABELS
  51.         SYMBOLS                         ; GENERATE 10 MORE LABELS
  52.         REPT 3                          ; GENERATE 3 MORE LABELS
  53.                 SYM_SUPP1       %?CNT1
  54.                 SYM_SUPP2       %?CNT1
  55.                 ?CNT1 = ?CNT1 + 1
  56.         ENDM
  57. ;
  58. END     START