Cebollita

Cebollita Assembler Specification

Last modified: April 14, 2005
Sloop SMOK
  CSE Home  About Us    Search    Contact Info 

Cebollita MIPS Assembler Specification

This package contains classes for assembling files that contain both a restriction of and an expansion of MIPS assembly, and then linking the object files produced into executables. 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, SLTI
Logic
AND, ANDI, OR, ORI, AND, XOR, SLL, SLLV, SRA, SRAV, SRL, SRLV, XOR, XORI
Memory
LB, SB, LW, SW
Control
J, JAL, JALR, JR, BEQ, BNE, BLEZ, BGTZ
Random
SYSCALL, NOP, RFE, BREAK
[MFC0, MTC0, MFLO, MFHI - supported only in the deprecated Cebollita "Classic" architecture]
Cebollita-invented
HALT
(*) 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. Also, the C-- compiler generates only a subset of these instructions, and so a project machine implementation capable of supporting compiler generated executables need implement only a subset.

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.

Static 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 static data segment. .word asks the assembler to allocate 4 bytes initialized with the given value in the static data segment. .asciiz asks the assembler to allocate the given string in the static data segment. The assembler must (and does) automatically word-align data.

When used as immediate data, the value of the lables are the offsets within the static data segment.

Instruction 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.

By default, labels are local symbols, and are not exported. They can be declared global explicitly using the .global directive, as in:

        .global main
main:
Additionally, if an instruction label is used by an instruction whose encoding cannot be fully resolved until link time (all uses other than in a conditional branch), the label is implicitly promoted to global. All labels on static data items are global.

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
       .global __start
__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


Department of Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to zahorjan@cs.washington.edu]