home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mips / 818 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.5 KB  |  75 lines

  1. Newsgroups: comp.sys.mips
  2. Path: sparky!uunet!think.com!paperboy.osf.org!meissner
  3. From: meissner@osf.org (Michael Meissner)
  4. Subject: Re: Assembly code in C program
  5. In-Reply-To: 3jean@maas-neotek.arc.nasa.gov's message of Thu, 30 Jul 1992 05:31:41 GMT
  6. Message-ID: <MEISSNER.92Jul30115952@tiktok.osf.org>
  7. Followup-To: comp.sys.mips
  8. Sender: news@osf.org (USENET News System)
  9. Organization: Open Software Foundation
  10. References: <1992Jul29.191821.20283@gordian.com>
  11.     <1992Jul30.053141.21142@kronos.arc.nasa.gov>
  12. Date: 30 Jul 92 11:59:52
  13. Lines: 60
  14.  
  15. In article <1992Jul30.053141.21142@kronos.arc.nasa.gov> 3jean@maas-neotek.arc.nasa.gov (E.T.A.) writes:
  16.  
  17. | In article <1992Jul29.191821.20283@gordian.com> son@gordian.com (Son D. Nguyen) writes:
  18. | >Hi,
  19. | >
  20. | >I just had a quick question:
  21. | >
  22. | >Is there a way to place assembly code in the middle of
  23. | >a c routine?  For example:
  24. | >
  25. | If you have gcc, you can do this:
  26. | main()
  27. | {
  28. |   int count = 0;
  29. |   while(count < 10){
  30. |     count++;
  31. |     
  32. |     __asm__ volatile (".set noreorder");
  33. |     __asm__ volatile ("nop");
  34. |     __asm__ volatile ("nop");
  35. |     __asm__ volatile (".set reorder");
  36. |     
  37. |   }
  38. | }
  39.  
  40. If you are doing the above, you probably want to put all four lines in
  41. one string, separated by either ';' or \n\t.  GCC can still optimize
  42. stuff between the separate asm stuff.
  43.  
  44. | Note that you may want to use the .noreorder directive for
  45. | instructiosn like this otherwise you probably won't get what you want
  46. | out of the mips assembler. (The mips assembler normally rearranges
  47. | instructions.)
  48.  
  49. If you are using a recent GCC (such as 2.2.2), you can have GCC insert
  50. the .set noreorder's with:
  51.  
  52.     __asm__ __volatile__ ("%(nop\n\tnop%)")
  53.  
  54. Check out print_operand in config/mips.c for more %<letter> options
  55. that are supported.  I can't remember if it's in the last revision of
  56. OSF GCC 1.39 I released to the outside world.  I think it is.  The %(,
  57. %) stuff is not in the FSF versions of GCC 1.xx.
  58.  
  59. | The alternative is to code in assembly by compiling your code using -S
  60. | and then modifying the assembly code that it puts out. You can then
  61. | compile the .s file.
  62.  
  63. You lose any symbolic debug information except for line numbers in
  64. this case, since the MIPS compilers do not pass that information in
  65. the assembler (they bypass the first phase of the assembler and pass
  66. the symbol table directly to the second phase).
  67. --
  68. Michael Meissner    email: meissner@osf.org        phone: 617-621-8861
  69. Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
  70.  
  71. You are in a twisty little passage of standards, all conflicting.
  72.