[comp.os.msdos.programmer] TASM 2.0 and C-Language Specifier: The Real Story

ferencz@cwsys3.cwru.edu (Don Ferencz) (10/26/90)

Perhaps this will spare others the headaches it gave me... :-)

SUMMARY: Being relatively new to 80x86 assembler, I thought that the new
"language specifier" provided in Turbo Assembler (TASM) 2.0 would be quite
useful -- it's supposed to "hide" all the nasties of assembler (segments,
stack frames, the "_" in all C identifiers, etc.)  What I found was
I don't like having a lot of things hidden from me...

The C-language specifier lets you do nice things.  For example, if you
want to call your assembler routines from C, you should know that
C expects global variables and procedures to begin with an underscore.
Thus, once you declare a procedure or variable with "PUBLIC C MyProc",
TASM automatically converts the name to "_MyProc" everywhere in your code.

The nasty part came when I used the specifier in the ".MODEL" directive:

QUESTION: What does ".MODEL LARGE, C" do that ".MODEL LARGE" doesn't?
Even if you specify "C" with your model, you still need to use "C" when
you declare PUBLIC objects!

ANSWER: Using "C" along with the ".MODEL" directive automatically sets
up a C-like stack frame with "push bp; move bp,sp".  So the code:

	DOSSEG
	.MODEL	LARGE,C

	PUBLIC C MyProc Var1:WORD
MyProc	PROC
	mov	ax,1		; for example
	...

is the same as:

	PUBLIC _MyProc Var1:WORD
_MyProc	PROC
	push	bp		; TASM AUTOMATICALLY ADDS THESE LINES!!
	mov	bp,sp		;    ""      ""       ""
	mov	ax,1		; our code...
	...

It took frustration and some work with Turbo Debugger to discover this!
The problem is, in all the examples in the TASM Guide, they explicitly
perform the "push bp; mov bp,sp" -- which I was doing.  If you do this,
however, your stack now has *TWO* bp's pushed on it, and parameters passed
will be referenced wrong (in the code above, TASM will compile a reference
to "Var1" as [bp+6], when "Var1" is now at [bp+8]).

Note that, I think in general Borland's documentation is first-rate.
In this case, however, it looks like someone did a little patching from
the previous version, and left out some very important details of the
differences between using the specifier and not using it.

MORAL:  If you want something done right, do it yourself.  I don't use
the specifier in the ".MODEL" directive, and I set up my own stack frame.

--
===========================================================================
| Don Ferencz                       |  "And in the end/                   |
| ferencz@cwsys3.cwru.EDU           |   The love you take/                |
| Department of Systems Engineering |   Is equal to the love you make."   |
| Case Western Reserve University   |       -- The Beatles                |
===========================================================================