PowerPC Direct Build

I am new to PowerPC assembly. I work with MPC8245 (yes, old school). This is a processor of the 603e family.

I would like to know how to create an immediate boot instruction where the immediate 16-bit value is "unsigned".

Example: li r3,0xFC10

The cross gcc compiler, 4.4.5, which I use, does not allow this instruction, since the value is not a constant signed.

Yes, I could use minus the 2nd level add-on, but it makes reading and documenting the code difficult. When loading bit fields for device registers, accurate reading of bit fields in an instruction is much easier to read.

+5
source share
2 answers

li - - , addi.

addi rD, rA, SIMM SIMM rA, rD, , rA 0, 0 r0. li rD, SIMM addi rD, 0, SIMM.

0 - 0x7fff 0xffff8000 - 0xffffffff , .

(ori ..) 16- . "r0 0" addi.

0xfc10 : 0 li ( lis, 32- ), OR 16- ori.

, gcc :

$ cat test.c
unsigned int test(void)
{
    return 0xfc10;
}
$ gcc -O2 -c test.c
$ objdump -d test.o

test.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <test>:
   0:   38 60 00 00     li      r3,0
   4:   60 63 fc 10     ori     r3,r3,64528
   8:   4e 80 00 20     blr
   c:   60 00 00 00     nop
$

, GNU PowerPC. @h @l ( ) 16- , :

lis r3, 0x12345678@h            /* => li  r3, 0x1234     */
ori r3, r3, 0x12345678@l        /* => ori r3, r3, 0x5678 */

, ...

$ cat test2.s
        .macro  load_const rD, const
        .if (\const >= -0x8000) && (\const <= 0x7fff)
        li      \rD, \const
        .else
        lis     \rD, \const@h
        ori     \rD, \rD, \const@l
        .endif
        .endm

        load_const r3, 0
        load_const r4, 1
        load_const r5, -1
        load_const r6, 0x7fff
        load_const r7, 0x8000
        load_const r8, -32767
        load_const r9, -32768
        load_const r10, -32769
        load_const r11, 0xfc10

$ as -mregnames -o test2.o test2.s
$ objdump -d test2.o

test2.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <.text>:
   0:   38 60 00 00     li      r3,0
   4:   38 80 00 01     li      r4,1
   8:   38 a0 ff ff     li      r5,-1
   c:   38 c0 7f ff     li      r6,32767
  10:   3c e0 00 00     lis     r7,0
  14:   60 e7 80 00     ori     r7,r7,32768
  18:   39 00 80 01     li      r8,-32767
  1c:   39 20 80 00     li      r9,-32768
  20:   3d 40 ff ff     lis     r10,-1
  24:   61 4a 7f ff     ori     r10,r10,32767
  28:   3d 60 00 00     lis     r11,0
  2c:   61 6b fc 10     ori     r11,r11,64528
$ 
+10

16- ori, :

xor r3, r3, r3
ori r3, r3, 0xFC10
0

All Articles