[comp.os.msdos.programmer] TCC -S then using TASM and TLINK

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (02/07/91)

Lately I have been messing around with some stuff using TCC -S to make .ASM
output, then using TASM, TLINK, EXE2BIN, then REN file.BIN file.EXE....in
that order.  However....

I wrote a real simple program in inline assembly that saves your cursor
size, turns off the cursor (via setting the size to zero), swaps pages
to a blank page (arbitrarily it is page 2), then waits for a key to be
pressed...when a key is pressed, the cursor is turned back on and the page
swapped back to 0.

After I compiled this program using TCC -f- -mt -lt to produce a COM file
it came out to ~3000 bytes.  Next I did TCC -f- -mt -S, TASM OFF.ASM, then
TLINK OFF.ASM.  This resulted in an .EXE file of about 549 bytes.  I
then ran it through EXE2BIN, renamed the BIN file, then had a 37 byte
.COM file that WORKED!  Not bad for not really knowing 80x86 asm!

Anyway, after I had this wonderful experience using C as a shell of sorts
around assembly (let the C compiler do setup and clean up), I tried
converting an old program of mine, NMORE.C, that replaces the DOS MORE.COM
file.  The only difference is that it can page up a file and you use it
directly (NMORE FILE.TXT) instead of only as a pipe.

However, when I did the EXACT same routine as I listed above, I had no
errors whatsoever.  But it won't work.  It locks the machine up.  Is there
ANY reason that doing what I did with OFF.COM would not work with
NMORE.COM?  Here are the specifics:

NMORE.C:

Some C and assembly routines, 1 source file
NMORE.C does not containt ANY external routines..examining the .ASM output
confirms this.
TCC -mt -lt -f- NMORE.C works perfectly
TCC -mt -f- -S NMORE.C works just fine to produce .ASM
TASM NMORE.ASM does NOT produce a working EXE file, and changing it to
a .COM file does not help....


To sum, why would using TASM to compile .ASM files generated by TCC -S
NOT work?

Thanks for any help,

Brian

imp@Solbourne.COM (Warner Losh) (02/08/91)

In article <26755@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
>However, when I did the EXACT same routine as I listed above, I had no
>errors whatsoever.  But it won't work.  It locks the machine up.  Is there
>ANY reason that doing what I did with OFF.COM would not work with
>NMORE.COM?  Here are the specifics:

Does NMORE.C look something like:

int main (int argc, char **argv)
{
	if (argc == 1)
		more(NULL);
	else {
		while (--argc)
			more(*++argv);
	}
}

void more(char *fn)
{
...
}

If so, then you *MUST* link in C0.OBJ for your particular memory
model.  This module gets executed first and will set up things like
argc, argv, sets up global variables (eg _psp, _stklen, etc),  allows
signal handlers to work, etc.  If you are getting program sizes of 37
bytes, then there is no way you could be loading in this module as it
is about 1-2K (I'm not on my Rainbow right now, so I can't check for
sure).  If you don't link it in, then argc, argv, etc, won't be
pointing to anyplace meaningful, so when you go to access then, you
will more than likely be pointing to something off in cloud coocoo
land.  Also, if argc happens to be large, and your code looks like the
above code, it may take a while to try to open 20,000 files.

Warner

P.S.  It would help people answer your question if you *gasp* actually
posted the source to the program you are having problems with. :-)
-- 
Warner Losh		imp@Solbourne.COM
We sing about Beauty and we sing about Truth at $10,000 a show.

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (02/08/91)

>If so, then you *MUST* link in C0.OBJ for your particular memory
>model.  This module gets executed first and will set up things like
>argc, argv, sets up global variables (eg _psp, _stklen, etc),  allows
>signal handlers to work, etc.  If you are getting program sizes of 37
>bytes, then there is no way you could be loading in this module as it

Well, when we were using argv and argc we looked at the .ASM and
determined that it was in fact trying to link in another module due
to an external declaration for __setargv (?).  This, instead of using
argv we grab the PSP using offset 0x80 from the current segment.  This
works fine when I use TCC the entire route instead of .ASM

>
>P.S.  It would help people answer your question if you *gasp* actually
>posted the source to the program you are having problems with. :-)

Didn't post the source since it was too long, and since I am uploading
and posting on a SUN and I have the MS-DOS machine at home...well, that
is kind of a pain.  Thought there would be a simple solution, but 
I guess not.