home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19885 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  2.5 KB

  1. Path: sparky!uunet!haven.umd.edu!mimsy!mojo.eng.umd.edu!russotto
  2. From: russotto@eng.umd.edu (Matthew T. Russotto)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Assembly with C question...
  5. Message-ID: <1992Dec16.023307.16156@eng.umd.edu>
  6. Date: 16 Dec 92 02:33:07 GMT
  7. References: <1992Dec12.232559.265@physc1.byu.edu> <1992Dec13.215351.129652@watson.ibm.com>
  8. Organization: Project GLUE, University of Maryland, College Park
  9. Lines: 55
  10.  
  11. In article <1992Dec13.215351.129652@watson.ibm.com> arsouth@watson.ibm.com (Andrew R. Southwick) writes:
  12. >In <1992Dec12.232559.265@physc1.byu.edu> seth@physc1.byu.edu writes:
  13. >>Hi. I have a question about assembly language and C. Here is a snippet of
  14. >>C code, followed by the same thing disassembled.
  15. >> 
  16. >> 
  17. >>main()
  18. >>{
  19. >>       Init();
  20. >>       MakeMenus();
  21. >>       MakeWindow();
  22. >>       AddrsSet();
  23. >>       MakeGrid();
  24. >> 
  25. >> 
  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. >> 
  33. >> 
  34. >[...]
  35. >
  36. >Is this code in memory (i.e. disassembled while running) or taken from an 
  37. >ececuatable/code resource?  Probably the latter.
  38.  
  39. Actually, neither-- I missed the original post so I'll respond now.
  40. That code is before the link step.  It is when the project is linked
  41. that the proper A5 offsets are put in.
  42.  
  43. >What happens after the program is loaded is the segment loader (or some 
  44. >toolbox manager) steps in and replaces all these $0000's with real offsets
  45. >from building the jump table.  The jump table is located up in the A5 global
  46. >area, hence the A5.  The reason they won't point directly into code is to 
  47. >allow for multiple segments, and dynamic loading/unloading of them.  The JSR's
  48. >above leap to a small set of commands that either leaps back into the heap, or
  49. >calls a routine to load in the segment & then execute, depending on whether 
  50. >the segment is loaded or not.  Some development environments will handle this 
  51. >differently; as far as I know, both MPW and Think C both do it this way.
  52.  
  53. Aside from the first bit-- its the linker which puts in the real
  54. offsets, not any toolbox manager-- this is correct.
  55.  
  56. >[Man, I really miss a good text editor...]
  57.  
  58. You would prefer Xedit? <evil grin>
  59.  
  60.  
  61. -- 
  62. Matthew T. Russotto    russotto@eng.umd.edu    russotto@wam.umd.edu
  63. Some news readers expect "Disclaimer:" here.
  64. Just say NO to police searches and seizures.  Make them use force.
  65. (not responsible for bodily harm resulting from following above advice)
  66.