home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mips
- Path: sparky!uunet!think.com!paperboy.osf.org!meissner
- From: meissner@osf.org (Michael Meissner)
- Subject: Re: Assembly code in C program
- In-Reply-To: 3jean@maas-neotek.arc.nasa.gov's message of Thu, 30 Jul 1992 05:31:41 GMT
- Message-ID: <MEISSNER.92Jul30115952@tiktok.osf.org>
- Followup-To: comp.sys.mips
- Sender: news@osf.org (USENET News System)
- Organization: Open Software Foundation
- References: <1992Jul29.191821.20283@gordian.com>
- <1992Jul30.053141.21142@kronos.arc.nasa.gov>
- Date: 30 Jul 92 11:59:52
- Lines: 60
-
- In article <1992Jul30.053141.21142@kronos.arc.nasa.gov> 3jean@maas-neotek.arc.nasa.gov (E.T.A.) writes:
-
- | 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");
- |
- | }
- | }
-
- If you are doing the above, you probably want to put all four lines in
- one string, separated by either ';' or \n\t. GCC can still optimize
- stuff between the separate asm stuff.
-
- | 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.)
-
- If you are using a recent GCC (such as 2.2.2), you can have GCC insert
- the .set noreorder's with:
-
- __asm__ __volatile__ ("%(nop\n\tnop%)")
-
- Check out print_operand in config/mips.c for more %<letter> options
- that are supported. I can't remember if it's in the last revision of
- OSF GCC 1.39 I released to the outside world. I think it is. The %(,
- %) stuff is not in the FSF versions of GCC 1.xx.
-
- | 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.
-
- You lose any symbolic debug information except for line numbers in
- this case, since the MIPS compilers do not pass that information in
- the assembler (they bypass the first phase of the assembler and pass
- the symbol table directly to the second phase).
- --
- Michael Meissner email: meissner@osf.org phone: 617-621-8861
- Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
-
- You are in a twisty little passage of standards, all conflicting.
-