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

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!hela.iti.org!usc!rpi!deweeset
  3. From: deweeset@ptolemy3.rdrc.rpi.edu (Thomas E. DeWeese)
  4. Subject: Jump tables, and creating functions
  5. Message-ID: <g!j2!zf@rpi.edu>
  6. Nntp-Posting-Host: ptolemy3.rdrc.rpi.edu
  7. Organization: Rensselaer Polytechnic Institute, Troy, NY
  8. Date: Sun, 13 Dec 1992 20:03:53 GMT
  9. Lines: 51
  10.  
  11.   Hello, I am trying to write a program that will create a function, then
  12. call that function.  I think I have my program generating correct code, 
  13. but I can't seem to convice my program to JSR to it.
  14.   Let me expain my situation a little.  I am developing on a MacII, using
  15. Think C 5.0.4,  Under system 7.1.  There really is a good reason for writing
  16. self modifying code, in this case.  Namely this is a very time critical
  17. function, and the program generated function will be about 3-4 times faster 
  18. than any hand coded version could be.
  19.   Now I must admit that I am a bit of a novice when it comes to programming
  20. in assembly on a 68000, (I learned IBM370 assembly, about 4 years ago).
  21. But so far the real problem has been the function interface.  Here is what
  22. I have learned so far.  Functions in Think C are all referenced through a
  23. "Jump Table".  if you take the address of a function you will get a pointer
  24. to this jump table (which consists of a JSR <ea> followed by a RTS I think)
  25. where the <ea> is the actual address of the function.  This allows for
  26. functions to be moved in memory (as long as the jump table doesn't move), and
  27. it should even allow code segments to be unloaded (as long as you substitue
  28. a JSR to a function to load the code, and then jump to the proper address).
  29. All of that is pretty neat and well thought out.
  30.   But what I have is a pointer to the actual function I want to execute.
  31. EG the first thing is an UNLINK ...  Now I have already tried 
  32.  
  33. myfunc(windPtr, dataPtr);
  34.  
  35.   But it never even thought of working,  it didn't even make it to my code
  36. (I did a "g <address of my function>" command in Macs Bugs), and it
  37. hit an illegal instruction before it stopped at the top of my function.  BTW 
  38. I can't seem to trace the execution of my program with MacsBugs.  From the 
  39. Think Debugger, if I drop it into the monitor it seems to be in a little 
  40. function which simply brings the Think Debugger to the front (dropping it 
  41. out of MacsBugs!!),  I don't know if this is a bug in the Think Debugger 
  42. or in MacsBugs, but I don't think that this should be what happens.
  43.  
  44.   I also tried to do the JSR my self with
  45.  
  46. asm{
  47.     MOVE.L    windPtr,-(SP)
  48.     MOVE.L    dataPtr,-(SP)
  49.     JSR    myfunc
  50.     ADD.L    #0x08, SP
  51. }
  52.   Now I don't see how it could possibly not JSR to myfunc, but it didn't.
  53.   Am I missing something really important?
  54.   How do I use Macsbug with the Think Debugger.  It says the PC is four off
  55. but I don't think that has anything to do with it.
  56.   Where can I learn more about the internals of function calls on the mac?
  57.   I will try to read all replies to the news group, but if you mail me
  58. directly I will compile a summary of responses and my final solution (if
  59. I find one).  If I get my code working I will probably release it to the PD.
  60.                             Thomas DeWeese
  61. deweeset@rdrc.rpi.edu
  62.