/* Please only put a single text section. Do not play with sections, it just will make the program behave incorrectly */ .text /* This symbol is used only when creating a new psy-q file. */ start_pc: /* Internal relocations should work. That will generate a two-part R_MIPS_HI/LO16 relication, beeing lui $t0, xxx and lw $t0, yyy($t0) */ test0: lw $t0, test5 /* Absolute external jump. Will result in a R_MIPS_26 relocation, which is always possible. */ test1: j outside /* Relative external jump. Will result in a R_MIPS_PC16 relocation, which is not always possible. */ test2: b outside /* Plain address notification. Will result in R_MIPS32 relocations. */ test3: .word outside .word outside - 42 .word outside + 39 /* This is a two-part relocation, done using lui/addiu, by doing two relocations: R_MIPS_HI16 and R_MIPS_LO16. Note that the addiu will be a signed addition, so, the linker will take that in consideration before doing the R_MIPS_HI16 relocation. */ test4: la $t0, outside /* This is also a two-part relocation. The code will actually be expanded into: lui $t1, HI16(outside) addu $t1, $t2 lw $t1, LO16(outside)($t1) */ test5: lw $t1, outside($t2) /* The final relocation thing, still done using lui/addiu. This one will be expanded into: lui $at, HI16(outside) addu $at, $t2 lw $t2, LO16(outside)($at) */ test6: lw $t2, outside($t2) /* Finally, the internal relocations things to know: */ test7: b test7 /* This won't require relocation. However, the test7 symbol will be visible */ test8: j test8 /* This will require relocation, using R_MIPS_26 since it's absolute jump. */ /* Let's see misc stuff... */ /* This is a dangerous flag. Will tell the assembler to not insert any extra nop, nor to swap any jump. You have to know what you are doing if you really set this flag. */ .set noreorder /* Thanks to the noreorder flag, this code will fail when running on the real hardware, resulting in a hangup. */ test9: lw $t0, 0($t0) addu $t0, $t0 /* Let's enable back the flag */ .set reorder /* Now, there will be a "nop" insterted between the two instructions, allowing the code to run fine. */ test10: lw $t0, 0($t0) addu $t0, $t0 /* Still thanks to the reorder stuff, we can safely write this code, it will be reordered as: jal somefunction li $a0, 16 */ test11: li $a0, 16 jal somefunction /* That's all folks! */ .set noreorder b next next: j next2 next2: nop