home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!news
- From: arsouth@watson.ibm.com (Andrew R. Southwick)
- Subject: Re: Assembly with C question...
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <1992Dec13.215351.129652@watson.ibm.com>
- Date: Sun, 13 Dec 1992 21:53:51 GMT
- News-Software: IBM OS/2 PM RN (NR/2) v0.16 by O. Vishnepolsky and R. Rogers
- Lines: 58
- Reply-To: arsouth@watson.ibm.com (Andrew R. Southwick)
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <1992Dec12.232559.265@physc1.byu.edu>
- Nntp-Posting-Host: consult3.watson.ibm.com
- Organization: IBM T.J. Watson Research Center
-
- In <1992Dec12.232559.265@physc1.byu.edu> seth@physc1.byu.edu writes:
- >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...
-
- Is this code in memory (i.e. disassembled while running) or taken from an
- ececuatable/code resource? Probably the latter.
-
- What happens after the program is loaded is the segment loader (or some
- toolbox manager) steps in and replaces all these $0000's with real offsets,
- from building the jump table. The jump table is located up in the A5 global
- area, hence the A5. The reason they won't point directly into code is to
- allow for multiple segments, and dynamic loading/unloading of them. The JSR's
- above leap to a small set of commands that either leaps back into the heap, or
- calls a routine to load in the segment & then execute, depending on whether
- the segment is loaded or not. Some development environments will handle this
- differently; as far as I know, both MPW and Think C both do it this way.
-
- >Thanks,
- >Seth Leigh
- >BYU Physics Dept.
-
- [Man, I really miss a good text editor...]
-
- Violence is the last refuge of the incompetent. -- Salvor Hardin
- --------------------------------------------------------------
- My views are my own; behaviorists can stick THAT up their ***!
- Andrew R. Southwick
-