home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!usc!wupost!spool.mu.edu!agate!stanford.edu!apple!goofy!mumbo.apple.com!gallant.apple.com!seuss.apple.com!user
- From: absurd@apple.apple.com (Tim Dierks, software saboteur)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Assembly with C question...
- Message-ID: <absurd-131292134029@seuss.apple.com>
- Date: 13 Dec 92 22:07:23 GMT
- References: <1992Dec12.232559.265@physc1.byu.edu>
- Sender: news@gallant.apple.com
- Followup-To: comp.sys.mac.programmer
- Organization: MacDTS Marauders
- Lines: 71
-
- In article <1992Dec12.232559.265@physc1.byu.edu>, seth@physc1.byu.edu
- wrote:
- >
- > Hi. I have a question about assembly language and C. Here is a snippet of
- > C code, followed by the same thing disassembled.
- >
- >
- > main()
- > {
- > Init();
- > MakeMenus();
- > MakeWindow();
- > AddrsSet();
- > MakeGrid();
- >
- >
- > main:
- > 00000000 JSR $0000(A5)
- > 00000004 JSR $0000(A5)
- > 00000008 JSR $0000(A5)
- > 0000000C JSR $0000(A5)
- > 00000010 JSR $0000(A5)
- >
- >
- > My question is, why are all the function calls done in this way? How can I
- > tell what the offset relative to a5 is? I am confused. I have till now only
- > done assembly in the MDS (sad, sad) assembler. (yes, I was the one whining
- > about it a few weeks ago. The class is over, and now I can do assembly with
- > the inline assembler of THINK C like so many of you suggested...)
- > In the MDS Assembler we always could tell just what our offsets were,
- > becaused we used labels. I don't understand how all these function calls can
- > be made with an offset of $0000(a5). Isn't a5 the global area? Why are the
- > function calls going there anyways? Shouldn't they be going to the code area,
- > with offsets relative to the PC? I obviously don't see what is supposed to be
- > going on here, and I would appreciate it if one of you assembly gurus would
- > enlighten me...
- >
- > Thanks,
- > Seth Leigh
- > BYU Physics Dept.
-
- Here's the poop:
- (I don't know why that's there, I guess I just wanted to say "here's the
- poop", just once in my life. Forgive me.)
-
- Q: Why are all the offsets zero?
- A: You're looking at the assembly generated after compiling, not after
- linking.
- Because function offsets don't get generated until the program is linked,
- all
- the offsets are still 0; the zeros ar just placeholders for values which
- will
- get filled in by the linker later. If you want to see fully assembled &
- linked
- code, build your application and then look at the code with the ResEdit
- CODE
- Viewer (available at better ftp sites) or with MacsBug; you'll see the
- references in all their gory detail.
-
- Q: Why are they A5-relative addresses?
- A: There are two things (at least) stored in the A5 storage area: globals,
- as you are aware, and the jump table, which allows functions in one segment
- to call functions in another segment. The jump table contains code which
- links the segments together, loading them as necessary. Thus, to call a
- function in another segment, you jump to its jump table entry, which is
- generally at a positive offset from A5. If the function is in the same
- segment (which isn't determined until link time), then the call might
- get converted to PC-relative (this depends on a number of factors).
-
- Tim Dierks
- MacDTS, but today my shoes match!
-