Folding a constant into the instruction
Adding a small constant doesn't need a separate load. The compiler folds the number straight into the instruction using the immediate form, addi rD, rA, imm — imm is a literal value carried inside the opcode itself:
addi r3, r3, 5 # r3 = r3 + 5
blr
The immediate field is signed and 16 bits wide, so it reaches from -32768 to
- Ask for a constant bigger than that and the compiler splits the work across
lis plus addi — not something you need here, but worth filing away. And because the field is signed, the same addi can subtract as well. That's the next lesson.
The immediate in the target addi is the constant you're after.
Your task
Write adjust so it compiles to the target addi instruction.