# We give instructions to the assembler using # assembler directives, which all start with '.' # The "text" directive tells the assembler that # everything that follows goes in the text segment # of memory. .text # The first instruction of your program must have # the label "main" attached to it. # The conventional way to load a constant # into a register is to use the ori instruction # along with $zero. Note that this won't work # with numbers that cannot be represented in 16 bits. # # Load 12 into $t0. main: ori $t0, $zero, 12 # The assembler understands C hex notation as well, so this code # also stores 16 into $t1. ori $t1, $zero, 0x10 # Eventually, we will use pseudo-instructions to do this. # Now, print the contents of the registers # We print by making a system call. To make a syscall # 1) put the syscall number in $v0, and # 2) put the argument(s) in the $a0, $a1, ... # By convention, we move the contents of # one register into another using addu. addu $a0, $zero, $t0 # $a0 = $t0 # Then put 1 in $v0. 1 is the syscall number # for print_int. ori $v0, $zero, 1 # $v0 = 1 # Call the operating system syscall # Now print $t1 by moving it to $a0. # The value 1 (print_int) is still in $v0. addu $a0, $zero, $t1 # $a0 = $t1 syscall # print_int # The proper way to exit a program running in # spim is to use the jr instruction with register # $ra. jr $ra