Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ico!onecom!raid5!tony From: tony@raid5.uucp (Tony Andrews) Newsgroups: comp.sys.atari.st.tech Subject: Re: Sozobon asm Message-ID: <1990Sep21.142623.12807@raid5.uucp> Date: 21 Sep 90 14:26:23 GMT References: <18420004@hpsad.HP.COM> <6V0oP2w163w@bluemoon.UUCP> Reply-To: tony@raid5.UUCP (Tony Andrews) Organization: Array Technology Corp., Boulder, Colorado Lines: 35 In article <6V0oP2w163w@bluemoon.UUCP> archbold (Archie Jaszcz) writes: >randyh@hpsad.HP.COM (Randy Hosler) writes: >> After declaring program as a global >> above main() the code would compile because it now had a reference for >> _program. I don't know if everyone followed that, but I had a great time >> figuring it out. This is what the fragment now looks like. >> > The reason you couldn't get a reference of _program was just what >you wrote: it was not a global variable. When I first looked at a simple >dissassembled *.O file, I was surprised to see that main() does a LINK >instruction in assembly. In other words, all variables declared in main() >are simply going to be temporary as they exist only on stack, and not in >real GEMDOS data area. I think in object files you can only get >references to procedures and global variables (although I MAY be wrong), >since local variables are just offsets on a stack... There's nothing special about the function "main" in C except that it is the first function called, and it receives the command line arguments. Variables declared in main() go on the stack just as in any other function. Accessing local variables via embedded assembly is a bit of a pain in general because they are referenced via offsets from the frame pointer (in a6). At the request of some of our users we added a feature in version 1.2 to make this a little easier. The output of hcc now includes a comment block at the start of each function that shows all local variables and their offsets. --tony -- Tony Andrews uunet!dunike!onecom!raid5!tony Array Technology Corp. 4775 Walnut St., Suite B Boulder, Colorado 80301 USA