MIPS Assembler

Enter MIPS code below to see the assembler output.
Then copy the plain output to the MIPS Simulator interactive to run it.
Note: Only a subset of MIPS is implemented. Comments start with #.

Supported Instructions The following instructions are supported by both MIPS interactives:
sll, jr, add, addu, sub, subu, and, or, xor, nor, beq, bne, addi, addiu, andi, ori, xori, j
The la, li and move instructions are also supported and assembled to appropriate instructions from the list.
See all MIPS instructions on Wikipedia.

MIPS Input

Assembler Output

This simplified Javascript sandbox is based on the work of Alan J. Hogan.

.data str: .asciiz "\nHello World!\n" # You can change what is between the quotes if you like .text .globl main main: # Do the addition # For this, we first need to put the values # to add into registers ($t0 and $t1) # You can change the 30 below to another value li $t0, 30 # You can change the 20 below to another value li $t1, 20 # Now we can add the values in $t0 # and $t1, putting the result in special register $a0 add $a0, $t0, $t1 # Set up for printing the value in $a0. # A 1 in $v0 means we want to print an integer li $v0, 1 # The system call looks at what is in $v0 # and $a0, and knows to print what is in $a0 syscall # Now we want to print Hello World # So we load the (address of the) string into $a0. # The address of the string is too big to be stored # by one instruction, so we first load the upper half, # shift it across, then load the lower half la $a0, str # And put a 4 in $v0 to mean print a string li $v0, 4 # And just like before syscall looks at # $v0 and $a0 and knows to print the string syscall # Nicely end the program li $v0, 0 jr $ra
# Define the data strings .data go_str: .asciiz "GO!!!!!\n" new_line: .asciiz "\n" .text # Where should we start? .globl main main: # Put our starting value 5 into register $t0. We will update it as we go li $t0, 5 # Put our stopping value 0 into register $t1 li $t1, 0 # This label is just used for the jumps to refer to start_loop: # This says that if the values in $t0 and $t1 are the same, # it should jump down to the end_loop label. This is the # main loop condition beq $t0, $t1, end_loop # These three lines prepare for and print the current int # It must be moved into $a0 for the printing move $a0, $t0 li $v0, 1 syscall # These three lines print a new line character so that # each number is on a new line li $v0, 4 la $a0, new_line syscall # Add -1 to the value in $t0, i.e decrement it by 1 addi $t0, $t0, -1 # Jump back up to the start_loop label j start_loop # This is the end loop label that we jump to # when the loop condition becomes true end_loop: # These three lines print the “GO!!!!” string. li $v0, 4 la $a0, go_str syscall # And these two lines make the program exit nicely li $v0, 0 jr $ra