PowerPC assembler question

Erik de Castro Lopo mle+cl at mega-nerd.com
Sun Jun 16 16:30:41 EST 2013


Been busy, but I'm back looking at this.

David Laight wrote:

> With a scratch register there are some two instruction sequences.
> Reusing the destination register something like:
>
> 	addis	%r30,%r31,hi(.label - 1b)
> 	lwzx	%r30,lo(.label - 1b)(%r30)
>

I've managed to convert that into something gcc understands:

	addis	30, 31, (.label-(1b))@ha
	lwz	30, (.label-(1b))@l(30)

The "@l" is the equivalent of lo() and "@ha" is the sign extending
verions of hi(). Unfortunately, this code segfaults on executiion.
I suspect that is because I have used the LWZ instruction instead
of LWZX suggested by David.

Unfortunately gcc doesn't accept LWZX which I found documented
here:

     http://pds.twi.tudelft.nl/vakken/in101/labcourse/instruction-set/lwzx.html

and seems to have LX as a synonym, but that instruction only seems
to work on registers, not on addresses as we have here.

I'm actually beginning to have a better understanding of the code
and I've pulled out these snippets code code into a small assember
program I'm compiling with gcc and running under gdb.

Cheers,
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the Linuxppc-dev mailing list