Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!husc6!m2c!wpi!jhallen From: jhallen@wpi.wpi.edu (Joseph H Allen) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: TSR's with no assembly language Message-ID: <11433@wpi.wpi.edu> Date: 11 Apr 90 23:11:51 GMT References: <27810@siemens.siemens.com> <127@demott.COM> <28050@siemens.siemens.com> Reply-To: jhallen@wpi.wpi.edu (Joseph H Allen) Organization: Worcester Polytechnic Institute, Worcester ,MA Lines: 55 In article <28050@siemens.siemens.com> jrv@demon.siemens.com writes: >If there is anyone who can show me the method to use a local stack when my >MSC "all C" interrupt is called I would be most appreciative. I don't know about MSC but in TC: #include unsigned osp; /* Place to save old stack */ unsigned oss; unsiged localstack[1024]; interrupt foo() /* The interrupt call itself changes CS:PC, the function handler changes DS */ { osp=_SP; oss=_SS; disable(); _SS=_DS; _SP=(unsigned)localstack+1024; enable(); func(); /* Call to your code */ disable(); _SS=oss; _SP=osp; enable(); } Notes: This is for small & tiny model. You'll need to do different things for larger memory models: You'll have to set SS to a different value. You absolutely MUST NOT define any local variables in the interrupt handler- instead define them in the subfunction 'func()'. This is because if you define any local variables they will go on the old stack. This does put 18 bytes on the old stack for saving the registers (access these indirectly through osp and oss). This should be much safer than not changing the stack at all. Instead of allocating space for a stack, a better way is to have the TSR install code remember where the original stack was. It is probably possible to remove the 'disable()' and 'enable()'s. This is because the 8088 keeps interrupts off for the next intruction after loading SS. But check that the SP load is only a single instruction first before doing this (Note that in TC enable() and disable() are inline functions if you include dos.h). -- ~ COMPLETELY FUNCTIONAL SIGNATURE - NO FRIVOLITY HERE ~ REPLIES/FOLLOWUPS SHOULD BE SENT TO: jhallen@wpi.wpi.edu (130.215.24.1) DISCLAIMER: I'm personally resposible for everything I say. So, if you have a problem feel free to sue me.