Writing MIPS assembler instructions in C

M. Warner Losh imp at bsdimp.com
Thu Feb 25 05:42:10 UTC 2010


In message: <98a59be81002242126k5bbf5167p7cba4917c13d1256 at mail.gmail.com>
            "C. Jayachandran" <c.jayachandran at gmail.com> writes:
: On Thu, Feb 25, 2010 at 8:01 AM, Patrick Mahan <mahan at mahan.org> wrote:
: >
: > > %[foo] can be used to refer to named parameters (input or output,
: > > maybe even clobbered) of inline assembly instructions rather than
: > > using %0, %1, etc., which can be hard to read.  Consider:
: > >
: > > The brackets with the input and output parameters specify what names
: > > to use to refer to them in the assembly listing (here they happen to
: > > be mostly the same as the variable names, but that's not necessary.)
: > >
: >
: > Ah Sooo <*whack!*>......
: >
: > I did not even twig on that... I had gotten it in my head that %[rt]
: > was something special to the compiler that caused a certain behavior
: > to occur.
: >
: > Now my problem is I still need to force the value pointed to "addr" into
: > a specific register because there is a jalr to a function else where
: > that I only have binary access too and it expects it's a value in
: > that register.  Can I coerce this?
: 
: I may be missing something here,  but have you tried :
: 
: __asm__ __volatile__(
:            "ld     $8, 0(%0)\n\t"
:            "jalr   $8\n"
:            : : "r"(addr) : "$8");
: }
: 
: Or is there a reason this will not work?

Which register do you need to force it into?  Maybe it is something as
simple as:

	register_t r = *(register_t *)addr;

	foo(r);

if that register is a0...

Warner


More information about the freebsd-mips mailing list