home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / tools / pcmac / stack.asm < prev    next >
Assembly Source File  |  1991-05-22  |  1KB  |  61 lines

  1. ;STACK.ASM
  2. ;Demonstration program for the usage of stack directives
  3.  
  4. NONADDRESS EQU    -1 ;Any value that can not represent address
  5.  
  6. #list off
  7.  
  8. ;A simple jump instruction
  9. macro("JP *",NUMERIC)
  10.     DB    0C3h
  11.     DW    #0
  12. endm
  13.  
  14. ;LOOP macro definition nestable with break
  15. macro("LOOP")
  16. #ifndef loop_stack
  17. var loop_stack,code_counter_store,address
  18. #stack loop_stack
  19. #endif
  20. #push loop_stack , NONADDRESS
  21. #push loop_stack , $
  22. endm
  23.  
  24. ;BREAK macro definition
  25. macro("BREAK")
  26.     JP    0 ; We do not know the address now
  27. #push loop_stack , $-2  ;Store the address of
  28.             ;the second byte of the instruction
  29. endm
  30.  
  31. ;ENDLOOP macro definition that fills in the BREAK jumps
  32. macro("ENDLOOP")
  33. code_counter_store := $
  34. address := pop(loop_stack)
  35. #while tos(loop_stack) != NONADDRESS
  36. $ := address
  37.     DW code_counter_store+3 ; 3 is the length of
  38.               ; the jump-back instruction
  39. address := pop(loop_stack)
  40. #wend
  41. $ := code_counter_store
  42.     JP    address
  43. #pop    loop_stack
  44. endm
  45.  
  46. #if pass = 2
  47. #list on
  48. #endif
  49.  
  50.     LOOP      ;*  loop #1
  51.     LOOP      ; * loop #2
  52.     BREAK
  53.     BREAK
  54.     ENDLOOP   ; * endloop #2
  55.     BREAK
  56.     LOOP      ; * loop #3
  57.     BREAK
  58.     ENDLOOP   ; * endloop #3
  59.     BREAK
  60.     ENDLOOP   ;* endloop #1
  61. ;End of file STACK.ASM