Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site gitpyr.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gatech!gitpyr!cc100jr From: cc100jr@gitpyr.UUCP (Joel M. Rives) Newsgroups: net.micro.pc,net.lang.pascal Subject: Re: local variable in assembly routine to be call from TURBO PASCAL Message-ID: <1062@gitpyr.UUCP> Date: Thu, 21-Nov-85 09:13:10 EST Article-I.D.: gitpyr.1062 Posted: Thu Nov 21 09:13:10 1985 Date-Received: Sat, 23-Nov-85 04:36:20 EST References: <1165@princeton.UUCP> Reply-To: cc100jr@gitpyr.UUCP (Joel M. Rives) Distribution: net Organization: Office of Computing Services, Georgia Tech Lines: 46 Xref: watmath net.micro.pc:5956 net.lang.pascal:387 In article <1165@princeton.UUCP> wei@princeton.UUCP (P Wei) writes: > >My final goal is to set a 'static local variable' (like in C) such that on >second entry into this routine I can still get the value of variable set last >time. From the TURBO reference manual, the local variable is stored in stack >segment. So I think the above routine is not going to work. Can anyone tell >me a workable procedure ? >Thanks. >HP Wei (wei@princeton) ------------------------------------------------------------------------------ One way to ensure the integrity of a local variable in Turbo Pascal is to take advantage of the "absolute" declaration. Start by generating space for the variable (or table of variables if you need) either in the main program or through dynamic allocation (the later method is not suggested, however, as the results are unpredictable should you release the heap at any other point in the program). In your procedure, declare the variable as "absolute" over the global variable already established. This bit of gymnastics is absurd, though, sense you could simply use the global variable directly. If you consider the method that Pascal uses for providing space for variables, you will realize that use of global references are the only viable means of doing what you want to do. Every time you enter a procedure or function, a fresh (theoretically undefined) section of memory is set aside for all of the local variables. This allocation of space is dynamic in the sense that it is provided upon demand. Therefore, the second time that you enter a procedure, it is very unlikely that it will be mapped directly over the exact same spot in memory that it occupied the first time. It is possible to ensure that such a thing happens by forcing the program to load at a higher address than it would normally. By doing so, you will have left a chunk of memory (between the address in memory where the loader would have put the program and the address where you instructed it to load the program). This chunk of memory is totally transparent to the program in that it will perform no memory management upon that section of memory. You can then reference that location either through "absolute" declarations or the Mem(csect:address) function. In any case, use of global references - where neccissary - is not an evil. the never-present whisper spirit Joel Rives Georgia Insitute of Technology, Atlanta Georgia, 30332 ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!cc100jr "Remember, no matter where you go, there you are!" << Buckaroo Banzai >>