home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / tcmac / tmacs.asi next >
Text File  |  1987-07-11  |  8KB  |  381 lines

  1. ;
  2. ;    tmac.asi    An assembler include file containing macros to 
  3. ;            automate the segmentation of assembly source files 
  4. ;            to be used with Turbo-C. 
  5. ;
  6. ;            See the end of the file for examples of and notes on
  7. ;            using these macros.
  8. ;
  9. ;    Author:        Richard Hargrove
  10. ;            Texas Instruments, Inc.
  11. ;            P.O. Box 869305, m/s 8473
  12. ;            Plano, TX 75086
  13. ;            214/575-4128
  14. ;
  15. ;------------------------------------------------------------------------------
  16. ;
  17. model        macro    mod_name
  18. ;;
  19. ;; usage:    model    mod_name
  20. ;;
  21. ;; parameters:    mod_name ::= { TINY | SMALL | COMPACT | MEDIUM | LARGE | HUGE }
  22. ;;
  23. ;; Action:    defines the model name symbol used by the rest of the turbo 
  24. ;;        macros.
  25. ;;
  26. ;; Errors:    generates an error 94 if mod_name is not specified
  27. ;;
  28.         ifndef    __@model_called
  29. __@model_called equ    1
  30.         .errb    <mod_name>
  31. __@TINY        =    0
  32. __@SMALL    =    0
  33. __@COMPACT    =    0
  34. __@MEDIUM    =    0
  35. __@LARGE    =    0
  36. __@HUGE        =    0
  37. ;
  38. __@&mod_name    =    1
  39.         endif
  40.         endm
  41. ;
  42. ;------------------------------------------------------------------------------
  43. ;
  44. segdef        macro    name
  45. ;;
  46. ;; usage:    segdef    name
  47. ;;
  48. ;; parameters:    name - module name
  49. ;;
  50. ;; action:    defines the _text, _data, and _bss segments; defines dgroup;
  51. ;;        sets the assume for the _text segment
  52. ;;
  53. ;; errors:    MEDIUM, LARGE, and HUGE models - generates an error 94 if 
  54. ;;          the module name is not specified
  55. ;;        generates an error 89 if the macro model was not invoked
  56. ;;
  57. ;; handle _text segment
  58. ;;
  59.         ifndef    __@model_called
  60.         .err
  61.         %out    No Model defined
  62.         endif
  63.         if    __@TINY or __@SMALL or __@COMPACT
  64. _text        segment byte public 'code'
  65.         else
  66.         .errb    <name>
  67. name&_text    segment byte public 'code'
  68.         endif
  69.         ife    __@HUGE
  70. dgroup        group    _data,_bss
  71.         endif
  72.         if    __@TINY or __@SMALL
  73.         assume    cs:_text,ds:dgroup,ss:dgroup
  74.         endif
  75.         if    __@COMPACT
  76.         assume    cs:_text,ds:dgroup
  77.         endif
  78.         if    __@MEDIUM
  79.         .errb    <name>
  80.         assume    cs:name&_text,ds:dgroup,ss:dgroup
  81.         endif
  82.         if    __@LARGE
  83.         .errb    <name>
  84.         assume    cs:name&_text,ds:dgroup
  85.         endif
  86.         if    __@HUGE
  87.         .errb    <name>
  88.         assume    cs:name&_text,ds:name&_data
  89.         endif
  90.         if    __@TINY or __@SMALL or __@COMPACT
  91. _text        ends
  92.         else
  93. name&_text    ends
  94.         endif
  95. ;;
  96. ;; handle the _data and _bss segments
  97. ;;        
  98.         ife    __@HUGE
  99. _data        segment word public 'data'
  100. _data        ends
  101. _bss        segment    word public 'bss'
  102. _bss        ends
  103.         else
  104.         .errb    <name>
  105. name&_data    segment word public 'data'
  106. __@huge_data    equ    name&_data
  107. name&_data    ends
  108.         endif
  109.         endm
  110. ;
  111. ;------------------------------------------------------------------------------
  112. ;
  113. cseg        macro    name
  114. ;;
  115. ;; usage:    cseg    name
  116. ;;
  117. ;; parameters:    name - module name
  118. ;;
  119. ;; action:    opens the _text segment for code definition
  120. ;;
  121. ;; errors:    MEDIUM, LARGE, and HUGE models - generates an error 94 if 
  122. ;;          the module name is not specified
  123. ;;        generates an error 89 if the macro model was not invoked
  124. ;;
  125.         ifndef    __@model_called
  126.         .err
  127.         %out    tmacs macro error : no model defined
  128.         endif
  129.         if    __@TINY or __@SMALL or __@COMPACT
  130. _text        segment    byte public 'code'
  131.         else
  132.         .errb    <name>
  133. name&_text    segment    byte public 'code'
  134.         endif
  135.         endm
  136. ;
  137. ;------------------------------------------------------------------------------
  138. ;
  139. endcs        macro    name
  140. ;;
  141. ;; usage    endcs    name
  142. ;;
  143. ;; parameters:    name - module name
  144. ;;
  145. ;; action:    closes the _text segment
  146. ;;
  147. ;; errors:    MEDIUM, LARGE, and HUGE models - generates an error 94 if 
  148. ;;          the module name is not specified
  149. ;;        generates an error 89 if the macro model was not invoked
  150. ;;
  151.         ifndef    __@model_called
  152.         .err
  153.         %out    tmacs macro error : no model defined
  154.         endif
  155.         if    __@TINY or __@SMALL or __@COMPACT
  156. _text        ends
  157.         else
  158.         .errb    <name>
  159. name&_text    ends
  160.         endif
  161.         endm
  162. ;
  163. ;------------------------------------------------------------------------------
  164. ;
  165. dseg        macro    name
  166. ;;
  167. ;; usage    dseg
  168. ;;
  169. ;; parameters:    name - module name
  170. ;;
  171. ;; action:    opens the _data segment for data definitions
  172. ;;
  173. ;; errors:    HUGE model only - generates an error 94 if the module name 
  174. ;;          is not specified
  175. ;;        generates an error 89 if the macro model was not invoked
  176. ;;
  177.         ifndef    __@model_called
  178.         .err
  179.         %out    tmacs macro error : no model defined
  180.         endif
  181.         ife    __@HUGE
  182. _data        segment    word public 'data'
  183.         else
  184.         .errb    <name>
  185. name&_data    segment    word public 'data'
  186.         endif
  187.         endm
  188. ;
  189. ;------------------------------------------------------------------------------
  190. ;
  191. endds        macro    name
  192. ;;
  193. ;; usage    endds
  194. ;;
  195. ;; parameters:    name - module name
  196. ;;
  197. ;; action:    closes the _data segment
  198. ;;
  199. ;; errors:    HUGE model only - generates an error 94 if the module name 
  200. ;;          is not specified
  201. ;;        generates an error 89 if the macro model was not invoked
  202. ;;
  203.         ifndef    __@model_called
  204.         .err
  205.         %out    tmacs macro error : no model defined
  206.         endif
  207.         ife    __@HUGE
  208. _data        ends
  209.         else
  210.         .errb    <name>
  211. name&_data    ends
  212.         endif
  213.         endm
  214. ;
  215. ;------------------------------------------------------------------------------
  216. ;
  217. bseg        macro
  218. ;;
  219. ;; usage    bseg
  220. ;;
  221. ;; parameters:    none
  222. ;;
  223. ;; action:    opens the _bss segment for data definitions
  224. ;;
  225. ;; errors:    generates an error 89 if the macro model was not invoked
  226. ;;
  227.         ifndef    __@model_called
  228.         .err
  229.         %out    tmacs macro error : no model defined
  230.         endif
  231.         ife    __@HUGE
  232. _bss        segment    word public 'bss'
  233.         endif
  234.         endm
  235. ;
  236. ;------------------------------------------------------------------------------
  237. ;
  238. endbs        macro
  239. ;;
  240. ;; usage    endbs
  241. ;;
  242. ;; parameters:    none
  243. ;;
  244. ;; action:    closes the _bss segment
  245. ;;
  246. ;; errors:    generates an error 89 if the macro model was not invoked
  247. ;;
  248.         ifndef    __@model_called
  249.         .err
  250.         %out    tmacs macro error : no model defined
  251.         endif
  252.         ife    __@HUGE
  253. _bss        ends
  254.         endif
  255.         endm
  256. ;
  257. ;------------------------------------------------------------------------------
  258. ;
  259. procedure    macro    name, pub
  260. ;;
  261. ;; usage:    procedure    name, public
  262. ;;
  263. ;; parameters:    name - procedure name
  264. ;;        pub - if non-empty, declare the procedure public
  265. ;;
  266. ;; action:    defines a procedure header for the named procedure
  267. ;;
  268. ;; errors:    generates an error 94 if the procedure name is not specified
  269. ;;        generates an error 89 if the macro model was not invoked
  270. ;;
  271.         ifndef    __@model_called
  272.         .err
  273.         %out    tmacs macro error : no model defined
  274.         endif
  275.         .errb    <name>
  276.         if    __@TINY or __@SMALL or __@COMPACT
  277.         ifnb    <pub>
  278. _&name        proc    near
  279.         else
  280. name        proc    near
  281.         endif
  282.         else
  283.         ifnb    <pub>
  284. _&name        proc    far
  285.         else
  286. name        proc    far
  287.         endif
  288.         endif
  289.         ifnb    <pub>
  290. __@PUB        =    1
  291.         public    _&name
  292.         else
  293. __@PUB        =    0
  294.         endif
  295. ;
  296.         push    si        ;preamble code
  297.         push    di
  298.         push    bp
  299.         if    __@HUGE
  300.         push    ds
  301.         mov    bp,__@huge_data
  302.         mov    ds,bp
  303.         endif
  304.         mov    bp,sp
  305. ;
  306.         endm
  307. ;
  308. ;------------------------------------------------------------------------------
  309. ;
  310. endproc        macro    name
  311. ;;
  312. ;; usage:    endproc    name
  313. ;;
  314. ;; parameters:    name - procedure name
  315. ;;
  316. ;; action:    define the procedure termination code
  317. ;;
  318. ;; errors:    generates an error 94 if the procedure name is not specified
  319. ;;        generates an error 89 if the macro model was not invoked
  320. ;;
  321.         ifndef    __@model_called
  322.         .err
  323.         %out    tmacs macro error : no model defined
  324.         endif
  325.         .errb    <name>
  326. ;
  327.         if    __@HUGE
  328.         pop    ds
  329.         endif
  330.         pop    bp        ;wrap-up code
  331.         pop    di
  332.         pop    si
  333.         ret
  334. ;
  335.         if    __@PUB
  336. _&name        endp
  337.         else
  338. name        endp
  339.         endif
  340. ;
  341.         endm
  342. ;
  343. ;------------------------------------------------------------------------------
  344. ;
  345. if 0
  346. ;
  347. ; The follolwing is a simple example of using these macros. The invocation 
  348. ; of model and segdef should come before the others. After those, the order 
  349. ; of the segments is unimportant. 
  350. ;
  351. ; Notes:    Stylistically, the segmentation macros (segdef, cseg, endcs,
  352. ;        dseg, endds, bseg, and endbs) should probably always have the
  353. ;        module name specified as an actual parameter. Where it is not 
  354. ;        needed, it is ignored.
  355. ;
  356. ;        Remember that the procedure and endproc macros 1) contain 
  357. ;        preamble and epilog code, 2) add a leading underscore to the
  358. ;        proc name, and 3) should be assembled with the /mx (case
  359. ;        sensitive publics and externals) command line switch.
  360. ;
  361.         model    SMALL
  362.         segdef    foo        ;SMALL model ignores the module name
  363. ;
  364.         dseg    foo
  365. my_str        db    'A string',0dh, 0ah
  366. my_flag        dw    0
  367.         endds    foo
  368. ;
  369.         cseg    foo
  370. ;
  371. procedure    ret_zero, public
  372.         xor    ax,ax
  373.         endproc ret_zero
  374. ;
  375. procedure    bar
  376.         mov    dx, offset my_str
  377.         endproc    bar
  378. ;
  379.         endcs    foo
  380. endif
  381.