home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22111 < prev    next >
Encoding:
Text File  |  1993-01-25  |  2.0 KB  |  77 lines

  1. Path: sparky!uunet!usc!news.service.uci.edu!orion.oac.uci.edu!eapg070
  2. From: eapg070@orion.oac.uci.edu (Caroll Elke Pohl)
  3. Subject: Calling assembly from C
  4. Nntp-Posting-Host: orion.oac.uci.edu
  5. Message-ID: <2B639791.18213@news.service.uci.edu>
  6. Summary: using #pragma parameter doesn't work
  7. Newsgroups: comp.sys.mac.programmer
  8. Organization: University of California, Irvine
  9. Keywords: C,assembly
  10. Lines: 63
  11. Date: 25 Jan 93 07:32:33 GMT
  12. Distribution: usa
  13.  
  14. thanx to the many who responded to my earlier post.
  15. i took your suggestions but still i am stymied.
  16.  
  17. for those who don't remember, the challenge is to call an assembly language
  18. routine from C passing the parameters in registers (using MPW 3.3).
  19. towhit, i wrote the following source files:
  20.  
  21. /* test.c */
  22. #pragma parameter __D0 PLUS(__D0,__D1)
  23. long PLUS (long,long);
  24.  
  25. main ()
  26. {
  27.     long i,j,k;
  28.     i = 1;
  29.     j = 2;
  30.     k = PLUS (i,j);
  31. }
  32.  
  33. and of course:
  34.  
  35. ;test.a
  36. PLUS    proc    EXPORT
  37.         add.l    d1,d0
  38.         rts
  39.  
  40.         END
  41.  
  42. when linked together you would hope the C code would place i in D0,
  43. j in D1, a JSR to PLUS and finally D0 placed in k.
  44.  
  45. in fact however, i and j are pushed onto the stack and the whole program
  46. fails miserably.
  47.  
  48. as several good people pointed out, the syntax for these #pragma parameter
  49. statements can be found in "Memory.h".  however, in these declarations,
  50. the routines in question are really traps so they're declared more like
  51.  
  52. #pragma parameter __D0 FoobarTrap(__A0)
  53. long FoobarTrap (void*)=0xAAAA;
  54.  
  55. which, as you may surmise, inserts the trap 0xAAAA instead of a standard
  56. JSR. just for the fun of it, i declared my routine in this fashion to see
  57. how it would compile and, sure enough, i and j got placed in D0 and D1.
  58. of course the code was otherwise useless but it proved a point (what, i'm
  59. not sure).
  60.  
  61. so, can anyone explain this and/or offer a solution?
  62. i'm at my wits end.
  63.  
  64. help!
  65. please e-mail
  66.  
  67. -caroll
  68.  
  69. p.s., to the guy who suggested an inline jsr, i only wish MPW did
  70.  inline assembly!
  71.  
  72.                       ) """ (
  73.                        (Q Q)
  74.    Don't spook        (  |  )
  75.     the horse!         \ A /
  76.                        (___)
  77.