From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keith Wright To: crossgcc@sources.redhat.com Cc: robert.floyd@inet.com Subject: Re: Invalid Operands with Inline assembly Date: Thu, 26 Oct 2000 00:12:00 -0000 Message-id: <200010260706.DAA01070@fcs9.free-comp-shop.com> References: <39F74F0C.E2546F10@inet.com> X-SW-Source: 2000-10/msg00109.html > From: Robert Floyd > > I am attempting to embed inline assembly into my C code but during the > compilation, I keep getting the error "invalid operands for opcode". > Here is one of my lines: > > asm("mov %r14, %r15"); > > I don't see why this should cause an error. mov is a valid Hitachi SH > opcode, r14 and r15 are valid registers, the quotations are necessary as > well as the % before each register. Gcc uses a % to mark an argument that must be substituted by the compiler with some C expression. Thus you need two %%'s to get one through the compiler and into the assembler. Here is a chunk of embeded Motorola Coldfire code. It's written in CWEB, so ignore @ signs and the following character. Warning: I don't know squat about the Hitachi SH. @ The |trap_to_system| is the heart of the linkage between a user program and \coldboot/. It takes two parameters. The first is a count of the number of arguments (actually the number of quad words occupied by the argument list, but this should be the same thing in most cases). The macro will produce a trap whose number is the same as the argument count. The second parameter is a unique number that identifies the system call. To keep things consistent, new system call numbers should be created by adding to the |enum| types in |@|. There are four sets of numbers, one for each trap number. The macro expects to be used in an environment in which the variables |res| and |arglist| are defined. The variable |arglist| should be set up before invoking the macro to be a pointer to the first argument of the system call wrapper procedure. The variable |res| will contain the result of the system call, which is always an integer. That explanation, and the examples already done, should be enough to use the macro, if you should ever need to. To understand it, first read [6] \S 4.31, on using in-line assembly language in \.{gcc} and [3] \S 3.3.8 for an description of the sharp sign in \CEE/ macro definitions. @= #define trap_to_system(argc,calln)@/\ @[asm volatile(@/\ " move.l %1,%%d0; move.l %2,%%d1; trap #" #argc "; move.l %%d0,%0"@/\ : "=g" (res)@/\ : "g" (calln), "g" (arglist)@/\ : "%d0", "%d1")@]; \item{[3]} Samuel P.~Harbison and Guy L.~Steele~Jr., {\it \CEE/ A Reference Manual} (Fourth Edition), Prentice Hall (1995) \item{[6]} Richard M.~Stallman, {\it Using and Porting GNU CC}, Free Software Foundation (1996) -- -- Keith Wright Programmer in Chief, Free Computer Shop < http://www.free-comp-shop.com > --- Food, Shelter, Source code. --- ------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com