Path: utzoo!utgpu!attcan!ncrcan!ziebmef!stephen From: stephen@ziebmef.uucp (Stephen M. Dunn) Newsgroups: comp.sys.ibm.pc Subject: Re: More assembly questions about TSR development. Summary: TSR .EXEs, etc. Message-ID: <1989May6.201107.4925@ziebmef.uucp> Date: 7 May 89 00:11:06 GMT References: <4550@tekigm2.MEN.TEK.COM> Reply-To: stephen@ziebmef.UUCP (Stephen M. Dunn) Distribution: na Organization: Ziebmef Public Access Unix, Toronto, Ontario Lines: 60 In article <4550@tekigm2.MEN.TEK.COM> alanr@tekigm2.MEN.TEK.COM (Alan Rovner) writes: :1. Can a TSR be a .EXE file instead of a .COM file, at least during dev't? Yes, but there are some problems in using an EXE. The biggest such problem is that upon calling the DOS TSR service, you must say how many paragraphs (16-byte chunks of memory) you wish to remain in memory. With a COM, it's easy; divide the length of your file by 16 and round up. With an EXE, where you have many segments, it's not as easy. If you can find a way to do your TSR in a COM file (or, if that isn't possible, in a one-segment EXE), you'll find it's much easier to call the TSR function. :2. I've looked at a couple examples of working TSRs and noticed something :interesting. They don't have a stack segment defined. There is an :ASSUME CS:CODE,DS:CODE statement near the top but the stack isn't looked :at anywhere. In fact, the linker gives a warning that the stack segment :is missing. It doesn't seem to matter though, after running EXE2BIN it :works fine. I'm a little confused about this. This is quite normal, in fact it's required for a COM file. In a COM file, you are only allowed one segment, so you normally want CS and DS to point into that segment as both your code and your data are there. You don't define a stack segment; DOS gives you one when your COM is loaded into memory. The linker will always give such a warning when linking a program with no stack segment. The reason why is that you might not want to turn the EXE into a COM and it's just reminding you that you don't have a stack segment. I believe EXE2BIN will scream if you hand it an EXE with a stack segment. :3. In order to do a TSR exit from a routine, one of the parameters needed :by DOS is the memory size to be reserved in 16-byte paragraphs. I've seen :what look like tricky ways to determine this. Is there an easy way to :find where the end of your code is and I guess divide that by 16 to get the :number of paragraphs? I'm also a little confused about this too. This is where it really benefits you to have only one segment. Assuming you have a COM file, you can put a label (e.g. FILEND) at the end of your segment and calculate the number of paragraphs to reserve like this: NUM_2_RESERVE = (FILEND + 15) / 16 + 10H You add 15 to make sure that should FILEND fall in the middle of a para- graph, you chop the memory off after that paragraph rather than before it. Division by 16 is for an obvious reason; adding 10H is to allow space for the Program Segment Prefix (PSP; for more info, see Duncan's _Advanced MS-DOS Programming_ or one of Norton's books). I would imagine the same would apply for a one-segment EXE, but I'm not sure. BTW, to give credit where credit is due, the above formula is copied from memory but originally cam from the Duncan book cited above. Hope this helps. At the moment I'm studying TSRs because I want to write a print spooler (why? just for the pleasure of it :-), so my memory of the above should be correct. Regards, Steve -- ------------------------------------------------------------------------------- ! Stephen M. Dunn stephen@ziebmef.UUCP ! DISCLAIMER: Who'd ever ! ! (I am currently pondering a witticism to go here) ! claim such dumb ideas? ! -------------------------------------------------------------------------------