Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!rochester!cornell!sayde From: sayde@svax.cs.cornell.edu (Richard Sayde) Newsgroups: gnu.gcc Subject: Using asm in C code Message-ID: <31473@cornell.UUCP> Date: 27 Aug 89 20:57:44 GMT Sender: nobody@cornell.UUCP Reply-To: sayde@cs.cornell.edu (Richard Sayde) Distribution: gnu Organization: Cornell Univ. CS Dept, Ithaca NY Lines: 38 I am using asm to put assembley language instructions in my C code. I need to know if there is a way to tell if a data item is in memory or in a register. The problem comes up when I use the -O option or not (with -O local variables are allocated in registers and without they are allocated on the stack). So, when I access the data with an assembly instruction I need to use one type of instruction if it's in a register (with -O) and another instruction if it's on the stack (without -O). Is there a way to determine this in the asm statement so I don't have to change the code depending on whether I am optimizing or not? If the above is not clear, here is an example. { register int TempReg; int SavePSR; asm ("RDS %0,PSR" : "=r" (TempReg)); asm ("STW %1,%0" : "=m" (SavePSR) : "r" (TempReg)); } above is what I do if the variable SavePSR is on the stack. If it's a register I need to change the second as to asm ("ADD %0,%1,R0" : "=r" (SavePSR) : "r" (TempReg)); where R0 is a register that always has 0 in it. (Or maybe even optimize it furthur). So is there a way to determine if SavePSR is a memory or register variable? I am using GCC version 1.34. GCC is set up for a RISC processor similar to Berkely RISC. thanks for the help! Richard