|Informative Information for the Uninformed
Memory access on PowerPC is performed through the load and store instructions. Immediate values can be loaded to a register or stored to a location in memory, but the immediate value is limited to 16 bits. When using a load instruction on a non-immediate value, a base register is used, followed by an offset from that register to the desired location. Store instructions work in a similar fashion; the value to be stored is placed into a register, and the store instruction then writes that value to the destination register plus an offset value.3.2
Since each PowerPC instruction is 32 bits wide, it is not possible to load a 32-bit address into a register with a single instruction. The standard method of loading a full 32-bit value requires a load-immediate-shift (lis) followed by an or-immediate (ori). The first instruction loads the high 16 bits, while the second loads the lower 16 bits3.33.4. This 16-bit limitation also applies to relative branches and every other instruction that uses an immediate value.
;; ;; Load a 32-bit immediate value and store it to the stack ;; main: lis r5, 0x1122 ; load the high bits of the value ; r5 contains 0x11220000 ori r5, r5, 0x3344 ; load the low bits of the value ; r5 now contains 0x11223344 stw r5, 20(r1) ; store this value to SP+20 lwz r3, 20(r1) ; load this value back to r3