Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!ames!pasteur!ucbvax!hplabs!hpl-opus!hpccc!tomj From: tomj@hpccc.HP.COM (Tom Johnson) Newsgroups: comp.sys.ibm.pc Subject: Re: More assembly questions about TSR development. Message-ID: <5060057@hpccc.HP.COM> Date: 28 Apr 89 16:22:30 GMT References: <4550@tekigm2.MEN.TEK.COM> Organization: HP Corporate Computing Center Lines: 48 / hpccc:comp.sys.ibm.pc / alanr@tekigm2.MEN.TEK.COM (Alan Rovner) / 7:58 am Apr 26, 1989 / >1. Can a TSR be a .EXE file instead of a .COM file, at least during >development? I use CodeView a lot to test the things I'm writing and it >only works with .EXE files. If not, how does one go about testing their >TSRs? Speaking of CodeView, is it possible to debug an Interrupt Service >Routine? I don't think so, but I haven't explored it that closely. Yes, a TSR can be an .EXE file. The reason to go to an .EXE file would be to use different segments for data and code. Since TSR's are usually (hopefully) pretty small, this shouldn't matter. There is also a lot of extra work when DS, ES, and CS are different. For example, if you're in an interrupt and you need to access a variable, that variable has to be in the CS segment. (mov cs:var1,ax). I wouldn't do this just to run with CodeView though. CodeView ain't too good for TSR debugging. As far as I could tell, once you "terminate and stay resident," CodeView is done and you can't debug your actual routine. I'm also pretty sure you can't debug the interrupts with CodeView. >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. Lets see if I can remember this. When a .COM program is loaded, all the segment registers point to the same segment (including SS). The stack pointer should point to the end of the segment (0ffffh or something close). Therefore it doesn't do any good to define a stack. If you're writing a TSR as an .EXE file, then you need a stack, or at least set up your SS and SP registers when the program loads. >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. If it's a .COM file it's easy. Put a label at the start of the program and another one at the point where you want to release the memory, then subtract the first from the second. This gives the number of bytes between the two labels. Convert to paragraphs and you're set. Tom Johnson Hewlett-Packard tomj@hpccc.hp.com