home *** CD-ROM | disk | FTP | other *** search
- MAKING ASSEMBLER CODE PORTABLE
-
- Tinylib uses compiler-specific "include" files to take care of all the
- differences from one compiler's requirements to another. These files provide
- standardized macros to generate ASM code that meets a specific compiler's
- coding conventions. Separate include files for each compiler, and for each
- memory model within any compiler that permits a choice, are required. At
- present, include files for C86 V1.33 (small model), and for Aztec C V3.40
- (large model) are provided.
-
- Each file is a macro library. The one to be used should be copied with the
- name "COMPILER.INC". Each separate module source file in the Tinylib package
- begins with the directive "include compiler.inc", and makes extensive use of
- these macro facilities to accomodate global-symbol name conventions, memory
- models, storage allocation and reference, subroutine calling, and so forth.
- The standard macros defined, their parameters (if any), and their actions are
- described in the following paragraphs.
-
- Macro Name: ttl
- Parameters: modnam, vrsn, date, auth
- Defines module name, title line, and revision status for the module.
- Required as first macro in each module.
-
-
- Macro Name: dseg
- (no parameters)
- Defines start of data segment, and establishes compiler-specific segment-name
- or group-name. Required in each module even if data segment is not used.
-
-
- Macro Name: exterr
- (no parameters)
- Declares global error value symbol (as external). Actual symbol used depends
- on compiler's conventions. See also <moverr>, <geterr>, and <saverr>.
-
-
- Macro Name: defptr
- Parameters: ptrnam
- Defines <ptrnam> as a global symbol and reserves space to store a pointer
- value. May modify actual symbol as required by compiler conventions. Defines
- symbol as a WORD for small or program model, or as a DWORD for large or data
- model.
-
-
- Macro Name: extv
- Parameters: vname, type
- Defines <vname> as a global symbol external to the current module. May
- modify actual symbol as required by compiler conventions. Defines symbol type
- as <type>; no checks of <type> are made. Can be used for CODE or DATA.
-
-
- Macro Name: glblvl
- Parameters: list
- Permits several global symbols to be defined on one line of the source file.
- Parameter <list> is a list of parameter sets for macro <glblv>. Invokes
- <glblv> with first set as parameters, repeating until <list> is empty.
-
-
- Macro Name: glblv
- Parameters: vname, type, val
- Defines <vname> as a global symbol. May modify actual symbol as required by
- compiler conventions. Defines symbol to be of type defined by <type>,
- initialized to <val>.
-
- Valid Types: <byte> produces DB definition
- <word> produces DW definition
- <dword> produces DD definition
- No other symbols may appear as the <type>.
-
-
- Macro Name: cseg
- (no parameters)
- Defines end of data segment and start of code segment, and establishes
- compiler-specific segment-name or group-name. Required in each module even if
- code segment is not used.
-
- Macro Name: xtfs
- Parameters: list
- Permits several external functions to be defined on one line of the source
- file. Parameter <list> is a list of parameters for macro <extf>. Invokes
- <extf> with first parameter, repeating until <list> is empty.
-
-
- Macro Name: extf
- Parameters: fname
- Defines <fname> as a code-relative symbol external to the current module.
- Type (NEAR or FAR) is compiler-dependent and is automatically included. Symbol
- may be modified to comply with compiler conventions.
-
-
- Macro Name: moverr
- Parameters: val
- Sets global error value from <val> (which may be a register or a symbol
- reference). Actual symbol used for global error value depends on compiler's
- conventions. See <exterr>.
-
-
- Macro Name: geterr
- Parameters: val
- Gets global error value into <val> (which may be a register or a symbol
- reference. Actual symbol used for global error value depends on compiler's
- conventions. See <exterr>.
-
-
- Macro Name: saverr
- (no parameters)
- Copies global error value into stream table, assuming SI points to it.
- Actual symbol used for global error value depends on compiler's conventions.
- See <exterr>.
-
-
- Macro Name: procdef
- Parameters: pname, args
- Defines a global procedure with name <pname>. Symbol may be modified to
- conform to compiler's conventions. Saves BP and defines symbols to reference
- arguments passed to procedure as specified by the <args> list. Establishes
- PROC block which must be closed with <pend>. Note that these procedures may
- NOT be nested.
-
-
- Macro Name: dargs
- Parameters: list
- Interfaces procedure-defining macros <procdef> and <statdef> to the <darg>
- macro. Parameter <list> is a list of parameter sets for macro <darg>. Invokes
- <darg> with first parameter set, repeating until <list> is empty.
-
-
- Macro Name: darg
- Parameters: aname, type
- Equates <aname> to offset (BP-relative) for argument on stack. For strongly
- typed assemblers such as MASM, defines symbol same as <aname> with "_v"
- suffixed to be actual offset value, and defines <aname> as typed BP reference.
- Automatically maintains offset values using argument size obtained from <type>
- parameter.
-
- Valid Types: <byte> - 1 BYTE
- <word> - 1 WORD
- <dword> - 2 WORDs for "long" or "float" data
- <cdouble> - 4 WORDs for "double" data
- <ptr> - 2 or 4 WORDs for data pointer
- <fptr> - 2 or 4 WORDs for function pointer
- No other strings are valid for <type>.
-
-
- Macro Name: locs
- Parameters: list
- Terminates set of <dclv> declarations and adjusts SP value to reserve local
- variable space. Parameter <list> is a list of parameter sets for <dclv>. This
- macro should be used only once per procedure definition.
-
-
- Macro Name: dclv
- Parameters: lvnm, type, asiz
- Defines <lvnm> as a local automatic (BP-relative) variable with size
- determined by <type>. If <type> indicates an array, <asiz> is size of array;
- else <asiz> is ignored. Same typing considerations discussed for <darg> apply
- here; major difference between <darg> and <dclv> is the sign of the offset
- values.
-
- Valid Types: <byte> - 1 BYTE
- <word> - 1 WORD
- <dword> - 2 WORDs for "long" or "float" data
- <cdouble> - 4 WORDs for "double" data
- <ptr> - 2 or 4 WORDs for data pointer
- <fptr> - 2 or 4 WORDs for function pointer
- <baray> - array of BYTEs
- <iaray> - array of WORDs
- No other strings are valid for <type>.
-
-
- Macro Name: alias
- Parameters: pname, altnam
- Declares <altnam> to be equivalent to <pname>; used to provide alternate name
- for procedures such as "strchr()" and "index()". May modify actual symbol to
- conform to compiler's global-symbol conventions.
-
-
- Macro Name: entrdef
- Parameters: pname
- Declares <pname> as an alternate entry point for a global procedure,
- accepting the same list of arguments declared with macro <procdef> at the
- procedure's primary definition. May modify actual symbol to conform to
- compiler's global-symbol conventions.
-
-
- Macro Name: statdef
- Parameters: pname, args
- Local equivalent of <procdef>. Defines a static (local) procedure with name
- <pname>. Saves BP and defines symbols to reference arguments passed to
- procedure as specified by the <args> list. Establishes PROC block which must
- be closed with <iend>. Note that these procedures may NOT be nested.
-
-
- Macro Name: internal
- Parameters: pname
- Defines a static (local) procedure with name <pname> that has no arguments.
- Establishes PROC block which must be closed with <iend>. Note that these
- procedures may NOT be nested.
-
-
- Macro Name: intrdef
- Parameters: pname
- Local equivalent of <entrdef>. Declares <pname> as an alternate entry point
- for a local procedure, accepting the same list of arguments declared with macro
- <statdef> at the procedure's primary definition.
-
-
- Macro Name: callit
- Parameters: pname, args
- Generates complete call sequence to global procedure <pname>. Uses
- <pushargs> macro to push argument values listed in <args> onto stack, keeping
- count of the number of bytes pushed, issues CALL (modifying <pname> as required
- by compiler's conventions), and flushes stack upon return. Note that <args>
- list is processed left to right while C conventions usually require
- reverse-order stacking; thus arguments must appear in the REVERSE of their
- normal sequence in the <args> list.
-
-
- Macro Name: pushargs
- Parameters: list
- Interfaces procedure-calling macros such as <callit> to <pusharg>. Parameter
- <list> is a list of parameter sets for macro <pusharg>. Invokes <pusharg> with
- first parameter set, repeating until <list> is empty. Thus the LAST parameter
- set in the <list> will be at the lowest stack address when this macro
- terminates.
-
-
- Macro Name: pusharg
- Parameters: varib, type, segref
- Pushes word or words specified by <varib>, <type>, and <segref> onto stack as
- arguments for a call to another procedure. Number of words pushed is specified
- by parameter <type>. Parameter <segref> is used only when the <type> requires
- a segment reference. Maintains count of number of bytes pushed for use in
- flushing stack later.
-
- Valid Types: <byte> pushes 2 bytes onto stack from memory
- location <varib>.
- <word> pushes 2 bytes onto stack from memory
- location <varib>.
- <reg> pushes register <varib> onto stack.
- Must be 16-bit register; counts 2 bytes.
- <preg> pushes <segref> onto stack, followed by
- pointer register <varib>. If <segref> is
- omitted, uses default value for <varib>.
- Counts 4 bytes.
- <dword> pushes 4 bytes starting at memory location
- <varib> onto stack, by words. Word at
- <varib>+2 is pushed first.
- <cdouble> pushes 8 bytes starting at memory
- location <varib> onto stack, by words.
- Word at <varib>+6 is pushed first, then
- <varib>+4, <varib>+2, and <varib>.
- <ptr> pushes content of pointer <varib> onto
- stack. Counts 2 bytes in small or program
- model, 4 in data or large.
- <fptr> pushes address of memory reference <varib>
- onto stack. Counts 2 bytes in small or
- data model, 4 in program or large.
- Segment address is pushed first, in large
- or program model, followed by offset.
- No other strings are valid for <type>.
-
-
- Macro Name: pushptr
- Parameters: pointer
- For data or large model, pushes content of memory reference <pointer>[2] to
- the stack. For all models, pushes content of <pointer> to stack.
-
-
- Macro Name: popptr
- Parameters: pointer
- Inverse of macro <pushptr>; pops from stack into memory reference <pointer>
- for all models. For data or large model, then pops from stack into
- <pointer>[2].
-
-
- Macro Name: pshloc
- Parameters: vnam
- Pushes content of local variable <vnam> onto stack. Regardless of type
- declared for <vnam>, this macro references it as a WORD.
-
-
- Macro Name: psharg
- Parameters: anam
- Pushes content of argument <anam> onto stack. Like <pshloc>, the argument is
- referenced as a WORD.
-
-
- Macro Name: pushreg
- (no parameters)
- Generates PUSH DI/PUSH SI and sets HAVEREG flag to indicate that registers
- have been saved.
-
-
- Macro Name: popreg
- (no parameters)
- If HAVEREG is clear, does nothing. If set, generates POP SI/POP DI and
- clears HAVEREG flag to indicate that registers have been restored.
-
-
- Macro Name: pushds
- (no parameters)
- In small or program model, does nothing. In large or data model, generates
- PUSH DS and sets HAVEDS flag to indicate that DS has been saved.
-
-
- Macro Name: popds
- (no parameters)
- In small or program model, or if HAVEDS flag is clear, does nothing. In
- large or data model, if HAVEDS flag is set, generates POP DS and clears HAVEDS
- flag to indicate that DS has been restored.
-
-
- Macro Name: ldptr
- Parameters: dest, argname, segref
- Loads register <dest> from memory reference <argname>. In small or program
- model, generates a MOV <dest>,<argname> instruction and the <segref> parameter
- is ignored.
- In data or large models the macro is much more complex: If <segreg> is "DS",
- a "LDS" instruction is generated. If it is "ES", a "LES" instruction results.
- If <segreg> is omitted, a "LDS" is generated for <dest> of "SI", "LES" for
- "DI", and any other value for the <dest> parameter produces an error message.
- If <segreg> is present and is any other value, a pair of MOV instructions are
- generated. The first loads <dest> from <argname> and the second loads <segref>
- from <argname>[2].
-
-
- Macro Name: svptr
- Parameters: dest, argname, segref
- Stores an arg pointer from registers <segref>:<dest> into 4 bytes of memory
- starting at <argname>, in standard offset:segment format, for data or large
- models. If <segref> is missing, determines default value by rules similar to
- those described for macro <ldptr>. For small or program model, ignores
- <segref> and stores register <dest> in WORD at <argname>.
-
-
- Macro Name: setptr
- Parameters: ptrnam, sym, segref
- Sets global, static, or auto memory location <ptrnam> to point to address
- <segref>:<sym>. In small or program memory model, parameter <segref> is
- ignored; if omitted large or data model macro will assign default. Note that
- AX is destroyed.
-
-
- Macro Name: ptrcpyinc
- Parameters: from, to
- Copies value pointed to by parameter <from>, into global, static, or auto
- memory location <to>, and post-increments pointer <from>. Uses register AX
- (and DX in the large or data model) for the transfer; fetches with macro <gwi>.
-
-
- Macro Name: extraseg
- (no parameters)
- Forces ES to same value as DS, by PUSH/POP sequence. No other registers or
- flags are affected.
-
-
- Macro Name: gci
- Parameters: ptrnam
- Fetches single byte pointed to by <ptrnam> into AL register and
- post-increments <ptrnam>. Uses the <ldptr> macro to load SI register from
- <ptrnam>, LODSB to fetch byte and increment SI, and <svptr> macro to store
- incremented register back into <ptrnam>. Use primarily for single- byte
- actions; if more than a couple of bytes are to be fetched, separate <ldptr>,
- LODSB, and <svptr> calls have much less overhead.
-
-
- Macro Name: pci
- Parameters: ptrnam
- Inverse of <gci> macro above. Stores AL register where <ptrnam> points,
- using DI register, and post-increments <ptrnam>. Same overhead considerations
- apply.
-
-
- Macro Name: gwi
- Parameters: ptrnam
- Same as <gci> except that it moves a 16-bit word into AX. All considerations
- apply.
-
-
- Macro Name: pwi
- Parameters: ptrnam
- Same as <pci> except that it moves a 16-bit word from AX. All considerations
- apply.
-
-
- Macro Name: caseb
- Parameters: val, goto
- Compares content of AL with parameter <val>, which may be constant, memory
- reference, or register. If equal, branches to "short label" <goto>.
-
-
- Macro Name: casew
- Parameters: val, goto
- Same as <caseb> except compares AX to <val>.
-
-
- Macro Name: retptrm
- Parameters: src
- Generates code to return a pointer value in DX:AX. If CY flag is set when
- this code is reached, a NULL pointer value is returned. If not, the value from
- memory location <src> (which may be relative to either BP or DS) is returned in
- AX, and that from the following word is returned in DX. Uses macro <pret> to
- generate actual return code.
-
-
- Macro Name: retptrr
- Parameters: src,seg
- Generates code to return a pointer value in DX:AX. If CY flag is set when
- this code is reached, a NULL pointer value is returned. If not, the value from
- <src> (which may be a memory reference or a register) is returned in AX, and
- that from <seg> is returned in DX. Uses macro <pret> to generate actual return
- code.
-
-
- Macro Name: retnull
- (no parameters)
- Generates code to return a NULL value in AX (and DX for large model). Uses
- macro <pret> to generate actual return code.
-
-
- Macro Name: retyes
- (no parameters)
- Generates code to return a value of 0001 in AX only. Uses macro <pret> to
- generate actual return code.
-
-
- Macro Name: pret
- (no parameters)
- Restores BP and registers, then executes RET. Note that since <pret> clears
- flags that indicate registers have been pushed, it must not be used more than
- once per procedure. Since the other "ret" macros all invoke <pret>, only one
- of this group should be used.
-
-
- Macro Name: iend
- Parameters: pname
- Ends definition of the static or internal procedure named <pname>.
-
-
- Macro Name: pend
- Parameters: pname
- Ends definition of the global procedure named <pname> (as modified by the
- macro which began the definition).
-
-
- Macro Name: finish
- (no parameters)
- Ends definition of the code segment and the module. Required for all
- modules; must be last line of source file.
-
- ============= end of description =============