Tut credits to FBD 1337.

lui t0 $XXXX
Loads the first 16Bits of your true controller address into t0 and shifts it left 16Bits. Add one here if the last 16Bits are 8000 or more.

lui t1 $XXXX
Loads the first 16Bits of your on value into t1 and shifts it left 16bits. Add one here if the last 16bits are 8000 or more.

addiu t1 t1 $XXXX
Adds the last 16Bits of your on value to the contents of t1 (First 16Bits of your value)
t1 = t1 + XXXX

sw t1 $XXXX(t0)
Stores the contents of t1 (On value) to the second 16bits of the address and to the contents of (t0) which is the first 16bits. So this line stores the on value to the address, there for creating a working code.

jr ra
Jumps to the return address, this turns your subroutine off, because it returns the addresses (and there corresponding values) back to the games original values, basically removing the MIPS we entered into your subroutine.

j $XXXXXXXX
Jumps to the beginning of your subroutine, this is what activates your subroutine after the jr ra takes place

Now I'll show you how I would write this code into a subroutine:
#Example Code
;Dose not work
0x0012345678 0xABCDEF12

I will start my subroutine at this address: 00000610 and I will use this hook: 00000098.

0x00000610 0x(Lui t0 $0892)
0x00000614 0x(Lui t1 $ABCE)
0x00000618 0x(Addiu t1 t1 $EF12))
0x0000061C 0x(Sw t1 $3456(t0))
0x00000620 0x(Jr ra)
0x00000098 0x(J $08800610)

and that is how a basic subroutine works.

-FBD