############################################################################## # # inst-examples.s # # This "program" is really just a collection of instruction examples to # illustrate what instructions do and how they are encoded in machine # language. # ############################################################################### .text # TEXT SEGMENT FOLLOWS # The main() function is called from the simple SPIM runtime environment # (coded in the exceptions.s file). It should do the work of the program. main: # ADD instruction example li $s1, 3 # Two numbers to add: 3 and 5 li $s2, 5 add $t8, $s2, $s1 # ADD example: $t8 = $s2 + $s1 # Expression evaluation example: Let g = (b + c) - (e + f) li $s2, 7 # Let b ($s2) = 7 li $s3, 11 # Let c ($s3) = 11 li $s5, 13 # Let e ($s5) = 13 li $s6, 17 # Let f ($s6) = 17 add $t8, $s2, $s3 # $t8 = $s2 + $s3 = b + c = 18 add $t9, $s5, $s6 # $t9 = $s5 + $s6 = e + f = 30 sub $s7, $t8, $t9 # $s7 = $t8 - $t9 = (b+c)-(e+f) = 18-30 = -22 # At this point, g ($s7) should contain the result, -22. # lui/ori example: Load 0xCafeDada into register $s0 li $s0, 0xDeadBeef # Initial garbage in $s0 lui $s0, 0xCafe # Load $s0 with 0xcafe0000 ori $s0, $s0, 0xDada # Logical-OR 0x0000dada into $s0. jr $ra # Return to runtime environment.