PPC Assembly Intro
PPC Assembly Intro
PowerPC Registers
General purpose registers (GRP)
32 32-bit registers: r0 to r31
Register usage Dedicated: data area anchor, stack pointer Volatile: Caller save Nonvolatile: Callee save
PowerPC Registers
Register R0 is different from R1-R31
Sometimes it is zero
addi r1, r0, 100 ; r1 <= 100
PowerPC Registers
Condition Register (CR)
Conditions of integer arithmetic operations Floating Point Status and Condition Register (FPSCR) Conditions of integer arithmetic operations
Data size
To read/write one byte, two bytes, or a whole word?
Extension
Register is always 32-bit (for 32-bit MPC555) Extend data as signed or unsigned number?
Addressing mode
How is the address given?
; r5 = 0x00000012 ; r5 = 0x00000034
; r5 = 0x00001234 ; r5 = 0x00005678
; r4 = 0x12345678
Zero extension: Fill the leftmost bits with zeros Algebraic extension: Fill the leftmost bits with the sign bit value
Examples:
stb r5, 0x1000(r3) sth r5, 0x1000(r3) stwx r5, r3, r4
op rD, d(rA)
op-code A B three registers) Other bits op rD, rA, rB D/S (arithmetic/logic using 5-bit 5-bit 11-bit 6-bit op rD, rA, rB 5-bit (load with register indexed) op rS, rA, rB (store with register indexed)
Examples
slw r5, r3, r4 sraw r5, r3, r4 slwi r5, r3, 1
Branch Instructions
Branch condition
Use conditions in the CR register
Branch Instructions
Condition register CR
CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 eight fields, 32-bit
LT GT EQ SO 4-bit
Branch Instructions
How to set condition?
Compare words
Branch Instructions
Compare unsigned signed words (compare logical)
cmplw rA, rB
cmplwi rA, IMM
Branch Instructions
Use LT, GT, EQ, SO bits in condition register bxx target
Examples: blt target ; branch taken if LT = 1 bgt target ; branch if GT = 1 beq target ; taken if EQ = 1 ble target ; taken if GT = 0 b target ; unconditional branch
Branch Instructions
C Program if (x > y) z = 1; else z = 0;
cmpw r3, r4 ble else addi r31, r0, 1 b done else: addi r31, r0, 0 done:
Notes: Revised from CodeWarrior disassemble x r3; y r4; z r31 li r31, 1 => addi r31, 0, 1; li called simplified mnemonic (pseudo-instruction)
; load immediate and shift by 16-bit lis rA, IMM ; addis, rA, r0, IMM
a = b;
a = 10;