Can I shorten this assembly code to test if a number is even? Here is MIPS code to return 1 if a number is even, 0 otherwise:
isEven:
  andi $t0, $a0, 1
  li   $t1, 1
  sub  $v0, $t1, $t0
  jr   $ra

My question is whether this can be done in fewer instructions. I could implement isOdd in two instructions (by eliminating the li and sub), but I don't see a single-instruction way to invert just the bottom bit of $t0 into $v0.
As was helpfully pointed out by G. Sliepen in a comment, you can flip the bottom bit using xor.
That enables the above code to be rewritten in one fewer instruction:
isEven:
  andi $t0, $a0, 1
  xori $v0, $t0, 1
  jr   $ra

This takes advantages of the properties:
A xor 1 = !A
A xor 0 = A