Cebollita MIPS Assembler Specification

This package contains classes for assembling files that contain MIPS assembly, and linking object files. The assembler is somewhat table driven, so the actual set of MIPS instructions that it handles can vary. However, here is the bare minimum set of instructions it can encode:
Arithmetic
ADD, ADDI, SUB, MULT*, DIV*, SLT
Logic
OR, ORI, AND, XOR, SLLV, SRAV, SRLV
Memory
LW, SW, LB, SB
Control
J, JAL, JR, BEQ, BNE, BLEZ, BGTZ
Random
SYSCALL, NOP, RFE, MFC0, MTC0, BREAK
(*) In the Cebollita world, MULT and DIV are implemented as regular R-type (three register) instructions. The high 32 bits (on a multiply) and the remainder (on a divide) are simply discarded.

Note that at present, there are no floating point instructions implemented.

MIPS assembly subset

The Cebollita MIPS assembler implements a subset of real MIPS assembly.

Instructions: It implements most of the standard R-type, I-type, and J-type instructions for arithmetic, control, and memory operations. It does not handle floating point instructions, or ANY pseudo-operations. Pseudo-ops are a lie that confuse the capabilities of the assembler, and have no real place in an introductory computer architecture setting.

Data: The following data directives are the only ones recognized:

[label] .space [bytes]
[label] .word  [value]
[label] .asciiz [string]
.space asks the assembler to allocate the given number of bytes of uninitialized space in the text segment. .word asks the assembler to allocate 4 bytes initialized with the given value in the data segment. .asciiz asks the assbler to allocate the given string in the text segment. The assembler must (and does) automatically word-align data.

Labels: Because of limitations of the linker, labels can ONLY be used in conjunction with BEQ, BNE, BGTZ, BLTZ, LW, SW, LB, SB, J, JAL, ADDI, ORI. Labels may begin with [_a-zA-Z] followed by zero or more characters in [_a-zA-Z0-9]. Label definitions must end in a colon.

Example

# compute the factorial of 9 using the following algorithm
#   N = 9
#   result = 1
#   while (N != 0) {
#     result = result * N
#     N = N - 1
#   }

.data					# begin data section
msg:    .asciiz  "The factorial is: "	# message string
		
.text                           # begin program text
__start:
	addi	$sp, $sp, -4		# make some space on the stack
        addi    $t0, $0, 1              # $t0 will hold result, initially 1
        addi    $t1, $0, 9              # $t1 will hold N, initially 9
top:	beq	$t1, $0, bottom
        mult    $t0, $t0, $t1           # result = result * N
        addi    $t1, $t1, -1            # decrement N
        j       top                     # goto top
bottom:
        sw      $t0, 0($sp)             # we'd better save result
        addi    $v0, $0, 4              # finished w/ loop, now print out
        addi    $a0, $gp, msg           # message, by invoking syscall 4
        syscall                         # (print_string)

        addi    $v0, $0, 1              # now print out result, by 
        lw      $a0, 0($sp)             # invoking syscall 1 (print_int)
        syscall

	addi	$sp, $sp, 4		# reset the stack
	addi	$v0, $0, 10		# exit syscall
	syscall