home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / stest / prologue.mac < prev    next >
Encoding:
Text File  |  1992-03-07  |  4.8 KB  |  243 lines

  1.  
  2. ;; A header macro file that defines a lot of common useful macros when
  3. ;; programming in assembly.  Supports conditional assembly for taking
  4. ;; advantage of 80286 opcodes.
  5.  
  6. IS286    equ    0        ;; True if taking advantage of 80286 opcodes.
  7.  
  8. Macro     SETUPSEGMENT
  9.  
  10. SEGMENT _TEXT    PARA PUBLIC 'CODE'
  11.     ASSUME    CS:_TEXT
  12.  
  13.     Endm
  14.  
  15.  
  16. macro   ShiftR  REG,TIMES
  17. ;; 2 - shift a register right a number of times.
  18. IF      IS286
  19.         shr     REG,TIMES
  20. ELSE
  21.         REPT    TIMES
  22.     shr    REG,1
  23.         ENDM
  24. ENDIF
  25.         endm
  26.  
  27. macro   ShiftL  REG,TIMES
  28. ;; 3 - shift a register left a number of times
  29. IF      IS286
  30.         shl     REG,TIMES
  31. ELSE
  32.         REPT    TIMES
  33.     shl    REG,1
  34.         ENDM
  35. ENDIF
  36.         endm
  37.  
  38. macro    LSMUL
  39. ;; 4 - performs a long signed multiply AX,DX * BX,CX
  40.     LOCAL    @@HOP1,@@HOP2
  41. ;; Long signed multiply
  42. ;; Long #1: AX,DX
  43. ;; Long #2: BX,CX
  44.     push    si
  45.     xchg    si,ax
  46.     xchg    dx,ax
  47.     or    ax,ax
  48.     jz    @@HOP1
  49.     mul    bx
  50. @@HOP1: xchg    cx,ax
  51.     or    ax,ax
  52.     jz    @@HOP2
  53.     mul    si
  54.     add    cx,ax
  55. @@HOP2: xchg    si,ax
  56.     mul    bx
  57.     add    dx,cx
  58.     pop    si
  59.     endm
  60.  
  61. macro    LongShiftL TIMES
  62. ;; 5 - Shift left AX,DX times.
  63.     REPT TIMES
  64.     shl    ax,1
  65.     rcl    dx,1
  66.     ENDM
  67.     endm
  68.  
  69. macro    LongShiftR TIMES
  70. ;; 6 - Shifr right AX,DX times
  71.     REPT TIMES
  72.     sar    dx,1
  73.     rcr    ax,1
  74.     ENDM
  75.     endm
  76.  
  77. macro    ShiftAL REG,TIMES
  78. ;; 7 - shift arithmetic left register, times
  79. IF      IS286
  80.     sal    REG,TIMES
  81. ELSE
  82.         REPT    TIMES
  83.     sal    REG,1
  84.         ENDM
  85. ENDIF
  86.     endm
  87.  
  88. macro    ShiftAR REG,TIMES
  89. ;; 8 - Shifr arithmatic right register, times
  90. IF      IS286
  91.     sar    REG,TIMES
  92. ELSE
  93.         REPT    TIMES
  94.     sar    REG,1
  95.         ENDM
  96. ENDIF
  97.     endm
  98.  
  99. macro   PushI   VALUE
  100. ;; 9 - Push an immediat onto the stack.
  101. ;; Push Immediate
  102. IF      IS286
  103.         push    VALUE
  104. ELSE
  105.         mov     ax,VALUE
  106.         push    ax
  107. ENDIF
  108.         endm
  109.  
  110. macro   PushEA  DATA
  111. ;; 10 - Push an effective address onto the stack.
  112. ;; Push Effective address
  113. IF      IS286
  114.         push    offset DATA
  115. ELSE
  116.         mov     ax,offset DATA
  117.         push    ax
  118. ENDIF
  119.         endm
  120.         
  121. macro   PushFar DATA
  122. ;; 11 - Push far address (relative to DS) onto the stack.
  123.         push    ds              ; push the segment
  124.         PushEA  DATA            ; push the offset
  125.         endm
  126.  
  127. macro   PushAll
  128. ;; 12 - Push ALL registers onto the stack.
  129. ;; Save all registers
  130. IF      IS286
  131.         pusha                   ;; if a 286 machine use the pusha opcode
  132.         push    ds              ;; save segment DS
  133.         push    es              ;; save segment ES
  134. ELSE
  135.         push    ax              ;; if not 286 machine use normal method
  136.         push    bx
  137.         push    cx
  138.         push    dx
  139.         push    si
  140.         push    di
  141.         push    bp
  142.         push    ds
  143.         push    es
  144. ENDIF
  145.         endm
  146.  
  147. macro   PopAll
  148. ;; 13 - Pop all registers off of the stack.
  149. ;;; Restore all registers from a push all
  150. IF      IS286
  151.         pop     es
  152.         pop     ds
  153.         popa
  154. ELSE
  155.         pop     es
  156.         pop     ds
  157.         pop     bp
  158.         pop     di
  159.         pop     si
  160.         pop     dx
  161.         pop     cx
  162.         pop     bx
  163.         pop     ax
  164. ENDIF
  165.         endm
  166.  
  167. macro   DOSTerminate
  168. ;; 14 - Terminate back to DOS
  169.     mov    ah,4Ch
  170.         int     21h
  171.         endm
  172.  
  173. macro   DosTSR  LOC
  174. ;; 15 - Terminate and stay resident back to DOS
  175.         lea     dx,[LOC+100h]   ; (End of program plus PSP)
  176.         int     27h             ; Terminate and stay resident.
  177.         endm
  178.  
  179. macro   Message data
  180. ;; 16 - Print a '$' terminated string to the console
  181.     push    ax
  182.         mov     ah,9            ; Function 9 write string
  183.         lea     dx,[data]       ; Get the address of the message
  184.         int     21h             ; Send the message to the screen.
  185.     pop    ax
  186.         endm
  187.  
  188.  
  189.  
  190. macro   PENTER  STORAGE
  191. ;; 17 - Enter a procedue with storage space
  192. ;; Procedure enter, uses the 286/386 ENTER opcode
  193. IF      IS286
  194.         enter   STORAGE,0       ; nexting level, always zero.
  195. ELSE
  196.         push    bp
  197.         mov     bp,sp
  198.         IF      STORAGE
  199.         sub     sp,STORAGE
  200.         ENDIF
  201. ENDIF
  202.         endm
  203.  
  204. macro   PLEAVE
  205. ;; 18 - Exit a procedure with stack correction.
  206. IF      IS286
  207.         leave
  208. ELSE
  209.         mov     sp,bp
  210.         pop     bp
  211. ENDIF
  212.         endm
  213.  
  214. macro   PushCREGS
  215. ;; 19 - Save registers for C
  216.         push    es
  217.     push    ds   ;The Kernel is responsible for maintaining DS
  218.         push    si
  219.         push    di
  220.         cld
  221.         endm
  222.  
  223. macro   PopCREGS
  224. ;; 20 - Restore registers for C
  225.         pop     di
  226.         pop     si
  227.     pop    ds ;The Kernel is responsible for maintaining DS
  228.         pop     es
  229.         endm
  230.  
  231. ;; Macro used to insert breakpoints in code to invoke the debugger.  Using
  232. ;; the macro allows for easier searches to be done on debug invokations.
  233. Macro    DoDebug
  234.     int    3
  235.     endm
  236.  
  237. Macro    SwapSegs
  238.     push    es
  239.     push    ds
  240.     pop    es
  241.     pop    ds
  242.     endm
  243.