[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: PowerPC assembler help



On Sun, Jun 09, 2013 at 04:45:24PM -0700, Brad Boyer wrote:
> On Sun, Jun 09, 2013 at 10:03:14PM +1000, Erik de Castro Lopo wrote:
> > Hi all,
> > 
> > Anyone know/understand PowerPC assembler?
> > 
> > I have the instruction:
> > 
> >     lwz     30, .label - (1b)(31)
> > 
> > >From reading the documentation I could find, I have figured out that
> > it loads a 16 bit value into register 30. The rest has got me somewhat
> > flumoxed. Clues?
> 
> I'm pretty sure that is loading a 32 bit value. I believe that 'h' is
> for 16 bit and 'w' is 32 bit. I haven't seen that syntax for the source,

Indeed, among "popular" architectures, "w" is more often 32 bit and "h" 
is used for 16 bit quantities. That's true for PPC, MIPS, ARM, SPARC, 
PARISC, and S390 at least.

X86 is the exception, since it started as a 16 bit processor and
so 32 bit is a "d" for doubleword (64 for the others) and 64 bit "q"
for quadword.

Well, digging into history, VAX and m68k used "w" for 16 bits and "l"
for 32 bits. For the VAX it was to be compatible with PDP11.


> but my guess would be that it is an assembler directive of some sort
> that will get translated into a memory reference of a register/offset,
> but it seems like it would need to be PC-relative which that instruction
> wouldn't support directly anyway.

That's a common idiom for PIC data references. This will happen quite
often if you use the -mrelocatable option. The compiler will set r31
with: 
	bl 1f
1:	mflr r31

and then use r31 as a base to access the data (normally read-only) 
that it has put with assembler directive just in front of the function.

	Gabriel


Reply to: