home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 4.ddi / LIB / SRC / MACROS < prev    next >
Encoding:
Text File  |  1990-12-16  |  3.9 KB  |  195 lines

  1. Word_size = 4        ; for the 386; min argument passed.
  2. ; Set pointer size.
  3. ifdef    Large_data
  4. Ptr_size    =    8       ; pass 8 bytes at a time for a 6-byte ptr.
  5. Ptr_reg     equ    es    ; Use es.
  6. Stack_reg    equ    ss    ; Use ss.
  7. else
  8. Ptr_size    =    4
  9. Ptr_reg     equ    ds    ; Can use ds, since = es.
  10. Stack_reg    equ    ds    ; Can use ds, since = ss.
  11. endif
  12.  
  13. ifdef    Small_code
  14. Pbase    =    8    ; Location of first parameter.
  15. Routine_size=    8    ; link + offset.
  16. return    macro    Pop_bytes
  17.   ifb    <Pop_bytes>
  18.     db    0c3h
  19.   else
  20.     db    0c2h
  21.     dw    Pop_bytes
  22.   endif
  23.     endm
  24. else
  25. Pbase    =    12      ; Location of first parameter.
  26. Routine_size=    12      ; Link + offset + segment.
  27. return    macro    Pop_bytes
  28.   ifb    <Pop_bytes>
  29.     db    0cbh
  30.   else
  31.     db    0cah
  32.     dw    Pop_bytes
  33.   endif
  34.     endm
  35. endif
  36.  
  37. prolog    macro
  38.     push    ebp
  39.     mov    ebp,esp
  40.     push    esi
  41.     push    edi
  42.     push    ebx
  43. ifdef    Large_data    ; Save DS whether or not 1 DS, in case we modify it.
  44.     push    ds
  45. endif
  46.     endm
  47. epilog    macro    Pop_bytes
  48. ifdef    Large_data
  49.     pop    ds
  50. endif
  51.     pop     ebx
  52.     pop    edi
  53.     pop    esi
  54.     pop    ebp
  55.     return    Pop_bytes
  56.     endm
  57.  
  58. ; We would have preferred a procbeg and procend macro, but
  59. ; the "proc" directive can't go inside a macro -- yet another
  60. ; of the many bugs in the flaky Microsoft assembler.
  61. publab    macro    procname
  62.     public    _mw&procname
  63. _mw&procname:
  64.     endm
  65. cseg    macro    segname,status
  66.     name    &segname
  67. ifb    <status>
  68. _mw&segname    segment dword 'CODE'
  69. else
  70. _mw&segname    segment dword 'CODE' public
  71. endif
  72.     assume    cs:_mw&segname
  73. ifdef    Small_code
  74. CGROUP    group    _mw&segname
  75.     assume    cs:CGROUP
  76. endif
  77.     endm
  78. endcseg macro    segname
  79. _mw&segname    ends
  80.     endm
  81. pubnames macro    names
  82.     irp    name,<names>
  83. ifdef   USING_MASM
  84.     public    _mw&&name
  85. else    
  86.     public    _mw&name
  87. endif   
  88.     endm
  89.     endm
  90. pubname macro    name
  91.     public    _mw&name
  92.     endm
  93. def    macro    x,y,z
  94. _mw&x    y    z
  95.     endm
  96. defequ    macro    x,y,z
  97. _mw&x    y    z
  98. x    equ    _mw&x
  99.     endm
  100. extequ    macro    x,type
  101.     extrn    _mw&x:type
  102. x    equ    _mw&x
  103.     endm
  104. ext    macro    x,type
  105.     extrn    _mw&x:type
  106.     endm
  107. ; Macros for parameter set-up that take care of small vs. large code
  108. ; and to some extent small vs. large data.
  109. ; Callling sequence:
  110. ;    parms    <<N1,T1>,<N2,T2>,...>
  111. ; where Ni are the names and Ti the types.
  112. ; This expands into
  113. ;    Ni equ T1 ptr offset[bp]
  114. ; where offset starts at the appropriate value for a procedure
  115. ; (assuming BP has been pushed, and taking into account small vs lg code)
  116. ; and is incremented as follows:
  117. ;    if Ti = "ptr" then increment by Ptr_size
  118. ;    otherwise increment by 2.
  119. ; For example:
  120. ;    parms    <<Src,word>,<Dest,ptr>,<Cnt,word>>
  121. ; generates
  122. ;    Src equ word ptr 6[bp]
  123. ;    Dest equ dword ptr 8[bp]
  124. ;    Cnt equ word ptr 12[bp]
  125. ; assuming parms start at 6.
  126. parm    macro    P,Type
  127.     local    Offset
  128. Offset    equ    Poff+0    ; +0 avoids alias; forces pass1 computation of expn.
  129. ifidn    <Type>,<ptr>    ; Type = "ptr"?
  130.   ifdef Small_data
  131. P    equ    dword ptr Offset[ebp]
  132.   else
  133. P    equ    pword ptr Offset[ebp]
  134.   endif
  135. Poff    =    Poff + Ptr_size
  136. else
  137. ifidn    <Type>,<routine>    ; Type = "routine"?
  138.   ifdef Small_code
  139. P    equ    word ptr Offset[ebp]
  140.   else
  141. P    equ    dword ptr Offset[ebp]
  142.   endif
  143. Poff    =    Poff + Routine_size - Word_size ; DOES NOT skip link.
  144. else
  145. P    equ    Type ptr Offset[ebp]
  146. Poff    =    Poff + Word_size
  147. endif
  148. endif
  149.     endm
  150. parms    macro    Parmlist
  151. Poff    =    Pbase    ; ret addr + pushed bp.
  152.     irp    P,<Parmlist>
  153.     parm    P
  154.     endm
  155.     endm
  156.  
  157. ; Load a pointer.
  158. ifdef    Small_data
  159. loadptr macro    Seginstr,Ireg,Operand
  160.     mov    Ireg,Operand
  161.     endm
  162. else
  163. loadptr macro    Seginstr,Ireg,Operand
  164.     seginstr Ireg,dword ptr Operand
  165.     endm
  166. endif
  167.  
  168. ; Load a formal routine parameter.
  169. ifdef    Small_code
  170. loadrout macro    Segreg,Ireg,Operand
  171.     mov    Ireg,Operand
  172.     push    cs
  173.     pop    Segreg
  174.     endm
  175. else
  176. loadrout macro    Segreg,Ireg,Operand
  177.     L&Segreg Ireg,dword ptr Operand
  178.     endm
  179. endif
  180.  
  181. ; Call a procedure.
  182. ifdef    Small_code
  183. pcall    macro    procname
  184. ifdef   USING_MASM
  185.         call    procname        ; MASM 5.1 BUG!!
  186.                     ; MASM doesn't put out proper LEdata for the call below.
  187. else
  188.      call    CGROUP:(near ptr procname)
  189. endif   
  190.     endm
  191. else
  192. pcall    macro    procname
  193.     call    far ptr procname
  194.     endm
  195. endif