home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19748 < prev    next >
Encoding:
Text File  |  1992-12-13  |  3.1 KB  |  74 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!news
  3. From: arsouth@watson.ibm.com (Andrew R. Southwick)
  4. Subject: Re: Assembly with C question...
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <1992Dec13.215351.129652@watson.ibm.com>
  7. Date: Sun, 13 Dec 1992 21:53:51 GMT
  8. News-Software: IBM OS/2 PM RN (NR/2) v0.16 by O. Vishnepolsky and R. Rogers
  9. Lines: 58
  10. Reply-To: arsouth@watson.ibm.com (Andrew R. Southwick)
  11. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  12. References: <1992Dec12.232559.265@physc1.byu.edu>
  13. Nntp-Posting-Host: consult3.watson.ibm.com
  14. Organization: IBM T.J. Watson Research Center
  15.  
  16. In <1992Dec12.232559.265@physc1.byu.edu> seth@physc1.byu.edu writes:
  17. >Hi. I have a question about assembly language and C. Here is a snippet of
  18. >C code, followed by the same thing disassembled.
  19. >main()
  20. >{
  21. >       Init();
  22. >       MakeMenus();
  23. >       MakeWindow();
  24. >       AddrsSet();
  25. >       MakeGrid();
  26. >main:
  27. >00000000        JSR       $0000(A5)
  28. >00000004        JSR       $0000(A5)
  29. >00000008        JSR       $0000(A5)
  30. >0000000C        JSR       $0000(A5)
  31. >00000010        JSR       $0000(A5)
  32. >My question is, why are all the function calls done in this way? How can I 
  33. >tell what the offset relative to a5 is? I am confused. I have till now only
  34. >done assembly in the MDS (sad, sad) assembler. (yes, I was the one whining
  35. >about it a few weeks ago. The class is over, and now I can do assembly with 
  36. >the inline assembler of THINK C like so many of you suggested...)
  37. >In the MDS Assembler we always could tell just what our offsets were, 
  38. >becaused we used labels. I don't understand how all these function calls can
  39. >be made with an offset of $0000(a5). Isn't a5 the global area? Why are the 
  40. >function calls going there anyways? Shouldn't they be going to the code area,
  41. >with offsets relative to the PC? I obviously don't see what is supposed to be
  42. >going on here, and I would appreciate it if one of you assembly gurus would 
  43. >enlighten me...
  44.  
  45. Is this code in memory (i.e. disassembled while running) or taken from an 
  46. ececuatable/code resource?  Probably the latter.
  47.  
  48. What happens after the program is loaded is the segment loader (or some 
  49. toolbox manager) steps in and replaces all these $0000's with real offsets,
  50. from building the jump table.  The jump table is located up in the A5 global
  51. area, hence the A5.  The reason they won't point directly into code is to 
  52. allow for multiple segments, and dynamic loading/unloading of them.  The JSR's
  53. above leap to a small set of commands that either leaps back into the heap, or
  54. calls a routine to load in the segment & then execute, depending on whether 
  55. the segment is loaded or not.  Some development environments will handle this 
  56. differently; as far as I know, both MPW and Think C both do it this way.
  57.  
  58. >Thanks,
  59. >Seth Leigh
  60. >BYU Physics Dept.
  61.  
  62. [Man, I really miss a good text editor...]
  63.  
  64. Violence is the last refuge of the incompetent. -- Salvor Hardin
  65. --------------------------------------------------------------
  66. My views are my own; behaviorists can stick THAT up their ***!
  67. Andrew R. Southwick
  68.