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

  1. Newsgroups: comp.sys.mips
  2. Path: sparky!uunet!sun-barr!ames!kronos.arc.nasa.gov!maas-neotek.arc.nasa.gov!3jean
  3. From: 3jean@maas-neotek.arc.nasa.gov (E.T.A.)
  4. Subject: Re: Assembly code in C program
  5. Message-ID: <1992Jul30.053141.21142@kronos.arc.nasa.gov>
  6. Followup-To: comp.sys.mips
  7. Summary: You can using gcc
  8. Sender: Eric Anderson <3jean@maas-neotek.arc.nasa.gov>
  9. Nntp-Posting-Host: maas-neotek.arc.nasa.gov
  10. Organization: NASA Ames Research Center
  11. References: <1992Jul29.191821.20283@gordian.com>
  12. Date: Thu, 30 Jul 1992 05:31:41 GMT
  13. Lines: 37
  14.  
  15. In article <1992Jul29.191821.20283@gordian.com> son@gordian.com (Son D. Nguyen) writes:
  16. >Hi,
  17. >
  18. >I just had a quick question:
  19. >
  20. >Is there a way to place assembly code in the middle of
  21. >a c routine?  For example:
  22. >
  23.  
  24. If you have gcc, you can do this:
  25.  
  26. main()
  27. {
  28.   int count = 0;
  29.  
  30.   while(count < 10){
  31.     count++;
  32.     
  33.     __asm__ volatile (".set noreorder");
  34.     __asm__ volatile ("nop");
  35.     __asm__ volatile ("nop");
  36.     __asm__ volatile (".set reorder");
  37.     
  38.   }
  39. }
  40.  
  41. Note that you may want to use the .noreorder directive for
  42. instructiosn like this otherwise you probably won't get what you want
  43. out of the mips assembler. (The mips assembler normally rearranges
  44. instructions.)
  45.  
  46. The alternative is to code in assembly by compiling your code using -S
  47. and then modifying the assembly code that it puts out. You can then
  48. compile the .s file.
  49.  
  50. -Eric Anderson
  51. 3jean@maas-neotek.arc.nasa.gov
  52.