home *** CD-ROM | disk | FTP | other *** search
- ;
- ; tmac.asi An assembler include file containing macros to
- ; automate the segmentation of assembly source files
- ; to be used with Turbo-C.
- ;
- ; See the end of the file for examples of and notes on
- ; using these macros.
- ;
- ; Author: Richard Hargrove
- ; Texas Instruments, Inc.
- ; P.O. Box 869305, m/s 8473
- ; Plano, TX 75086
- ; 214/575-4128
- ;
- ;------------------------------------------------------------------------------
- ;
- model macro mod_name
- ;;
- ;; usage: model mod_name
- ;;
- ;; parameters: mod_name ::= { TINY | SMALL | COMPACT | MEDIUM | LARGE | HUGE }
- ;;
- ;; Action: defines the model name symbol used by the rest of the turbo
- ;; macros.
- ;;
- ;; Errors: generates an error 94 if mod_name is not specified
- ;;
- ifndef __@model_called
- __@model_called equ 1
- .errb <mod_name>
- __@TINY = 0
- __@SMALL = 0
- __@COMPACT = 0
- __@MEDIUM = 0
- __@LARGE = 0
- __@HUGE = 0
- ;
- __@&mod_name = 1
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- segdef macro name
- ;;
- ;; usage: segdef name
- ;;
- ;; parameters: name - module name
- ;;
- ;; action: defines the _text, _data, and _bss segments; defines dgroup;
- ;; sets the assume for the _text segment
- ;;
- ;; errors: MEDIUM, LARGE, and HUGE models - generates an error 94 if
- ;; the module name is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ;; handle _text segment
- ;;
- ifndef __@model_called
- .err
- %out No Model defined
- endif
- if __@TINY or __@SMALL or __@COMPACT
- _text segment byte public 'code'
- else
- .errb <name>
- name&_text segment byte public 'code'
- endif
- ife __@HUGE
- dgroup group _data,_bss
- endif
- if __@TINY or __@SMALL
- assume cs:_text,ds:dgroup,ss:dgroup
- endif
- if __@COMPACT
- assume cs:_text,ds:dgroup
- endif
- if __@MEDIUM
- .errb <name>
- assume cs:name&_text,ds:dgroup,ss:dgroup
- endif
- if __@LARGE
- .errb <name>
- assume cs:name&_text,ds:dgroup
- endif
- if __@HUGE
- .errb <name>
- assume cs:name&_text,ds:name&_data
- endif
- if __@TINY or __@SMALL or __@COMPACT
- _text ends
- else
- name&_text ends
- endif
- ;;
- ;; handle the _data and _bss segments
- ;;
- ife __@HUGE
- _data segment word public 'data'
- _data ends
- _bss segment word public 'bss'
- _bss ends
- else
- .errb <name>
- name&_data segment word public 'data'
- __@huge_data equ name&_data
- name&_data ends
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- cseg macro name
- ;;
- ;; usage: cseg name
- ;;
- ;; parameters: name - module name
- ;;
- ;; action: opens the _text segment for code definition
- ;;
- ;; errors: MEDIUM, LARGE, and HUGE models - generates an error 94 if
- ;; the module name is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- if __@TINY or __@SMALL or __@COMPACT
- _text segment byte public 'code'
- else
- .errb <name>
- name&_text segment byte public 'code'
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- endcs macro name
- ;;
- ;; usage endcs name
- ;;
- ;; parameters: name - module name
- ;;
- ;; action: closes the _text segment
- ;;
- ;; errors: MEDIUM, LARGE, and HUGE models - generates an error 94 if
- ;; the module name is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- if __@TINY or __@SMALL or __@COMPACT
- _text ends
- else
- .errb <name>
- name&_text ends
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- dseg macro name
- ;;
- ;; usage dseg
- ;;
- ;; parameters: name - module name
- ;;
- ;; action: opens the _data segment for data definitions
- ;;
- ;; errors: HUGE model only - generates an error 94 if the module name
- ;; is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- ife __@HUGE
- _data segment word public 'data'
- else
- .errb <name>
- name&_data segment word public 'data'
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- endds macro name
- ;;
- ;; usage endds
- ;;
- ;; parameters: name - module name
- ;;
- ;; action: closes the _data segment
- ;;
- ;; errors: HUGE model only - generates an error 94 if the module name
- ;; is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- ife __@HUGE
- _data ends
- else
- .errb <name>
- name&_data ends
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- bseg macro
- ;;
- ;; usage bseg
- ;;
- ;; parameters: none
- ;;
- ;; action: opens the _bss segment for data definitions
- ;;
- ;; errors: generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- ife __@HUGE
- _bss segment word public 'bss'
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- endbs macro
- ;;
- ;; usage endbs
- ;;
- ;; parameters: none
- ;;
- ;; action: closes the _bss segment
- ;;
- ;; errors: generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- ife __@HUGE
- _bss ends
- endif
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- procedure macro name, pub
- ;;
- ;; usage: procedure name, public
- ;;
- ;; parameters: name - procedure name
- ;; pub - if non-empty, declare the procedure public
- ;;
- ;; action: defines a procedure header for the named procedure
- ;;
- ;; errors: generates an error 94 if the procedure name is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- .errb <name>
- if __@TINY or __@SMALL or __@COMPACT
- ifnb <pub>
- _&name proc near
- else
- name proc near
- endif
- else
- ifnb <pub>
- _&name proc far
- else
- name proc far
- endif
- endif
- ifnb <pub>
- __@PUB = 1
- public _&name
- else
- __@PUB = 0
- endif
- ;
- push si ;preamble code
- push di
- push bp
- if __@HUGE
- push ds
- mov bp,__@huge_data
- mov ds,bp
- endif
- mov bp,sp
- ;
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- endproc macro name
- ;;
- ;; usage: endproc name
- ;;
- ;; parameters: name - procedure name
- ;;
- ;; action: define the procedure termination code
- ;;
- ;; errors: generates an error 94 if the procedure name is not specified
- ;; generates an error 89 if the macro model was not invoked
- ;;
- ifndef __@model_called
- .err
- %out tmacs macro error : no model defined
- endif
- .errb <name>
- ;
- if __@HUGE
- pop ds
- endif
- pop bp ;wrap-up code
- pop di
- pop si
- ret
- ;
- if __@PUB
- _&name endp
- else
- name endp
- endif
- ;
- endm
- ;
- ;------------------------------------------------------------------------------
- ;
- if 0
- ;
- ; The follolwing is a simple example of using these macros. The invocation
- ; of model and segdef should come before the others. After those, the order
- ; of the segments is unimportant.
- ;
- ; Notes: Stylistically, the segmentation macros (segdef, cseg, endcs,
- ; dseg, endds, bseg, and endbs) should probably always have the
- ; module name specified as an actual parameter. Where it is not
- ; needed, it is ignored.
- ;
- ; Remember that the procedure and endproc macros 1) contain
- ; preamble and epilog code, 2) add a leading underscore to the
- ; proc name, and 3) should be assembled with the /mx (case
- ; sensitive publics and externals) command line switch.
- ;
- model SMALL
- segdef foo ;SMALL model ignores the module name
- ;
- dseg foo
- my_str db 'A string',0dh, 0ah
- my_flag dw 0
- endds foo
- ;
- cseg foo
- ;
- procedure ret_zero, public
- xor ax,ax
- endproc ret_zero
- ;
- procedure bar
- mov dx, offset my_str
- endproc bar
- ;
- endcs foo
- endif