home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mips
- Path: sparky!uunet!sun-barr!ames!kronos.arc.nasa.gov!maas-neotek.arc.nasa.gov!3jean
- From: 3jean@maas-neotek.arc.nasa.gov (E.T.A.)
- Subject: Re: Assembly code in C program
- Message-ID: <1992Jul30.053141.21142@kronos.arc.nasa.gov>
- Followup-To: comp.sys.mips
- Summary: You can using gcc
- Sender: Eric Anderson <3jean@maas-neotek.arc.nasa.gov>
- Nntp-Posting-Host: maas-neotek.arc.nasa.gov
- Organization: NASA Ames Research Center
- References: <1992Jul29.191821.20283@gordian.com>
- Date: Thu, 30 Jul 1992 05:31:41 GMT
- Lines: 37
-
- In article <1992Jul29.191821.20283@gordian.com> son@gordian.com (Son D. Nguyen) writes:
- >Hi,
- >
- >I just had a quick question:
- >
- >Is there a way to place assembly code in the middle of
- >a c routine? For example:
- >
-
- If you have gcc, you can do this:
-
- main()
- {
- int count = 0;
-
- while(count < 10){
- count++;
-
- __asm__ volatile (".set noreorder");
- __asm__ volatile ("nop");
- __asm__ volatile ("nop");
- __asm__ volatile (".set reorder");
-
- }
- }
-
- Note that you may want to use the .noreorder directive for
- instructiosn like this otherwise you probably won't get what you want
- out of the mips assembler. (The mips assembler normally rearranges
- instructions.)
-
- The alternative is to code in assembly by compiling your code using -S
- and then modifying the assembly code that it puts out. You can then
- compile the .s file.
-
- -Eric Anderson
- 3jean@maas-neotek.arc.nasa.gov
-