CS 39 -- Assmebler Documentation


Overview

This assembler is designed for the CS 39 Virtual Machine. It allows you to write mostly-normal assembly code, using labels to specify locations and using symbols to specify register numbers. This page describes the assembly code format and use of the assembler itself.


The register set

Below are listed the addressable registers for this architecture and the symbols used to refer to those registers conveniently in assembly code. A description of the typical use for each in assembly programming is provided:


Assembly code instruction format

The input format for the assembler is somewhat unusual due to its implementation in Scheme, a derivative of the LISP programming language. The code takes the following format (where the code snippet shown here does nothing interesting, and actually forms an infinite loop):

(
    (lbl-4 stri %g0 5)       ; Set %g0 to 5.
    (()    stri %t2 #x2e30   ; Set %t2 to hold hex value `2e30'
    (()    subr %g1 %g0 %t2) ; %g1 = %g0 - %t2

    ; A useless comment for demonstration purposes.
    (()    jmpi lbl-4)       ; Jump back to the top and repeat.
)
    

There are a number of elements of this format to observe:


Instruction Index

Below is a catalog of opcodes and their associated interpretation of the operands that follow. Specifically, in each description, we will refer to the opcode, as well as operand-0, operand-1, and operand-2. For each instruction, we will provide an example of its use.


How to use the assembler on sirius

Use of the VP assembler is reasonably simple. The only difficulty is in handling the errors. But first, a simple example of its use. Assume that we have a file name fib.vma in the current directory that you want to assemble. The following command will assemble it, placing the result in a file name fix.vmx:

assemble.sh fib

If the assembly code is syntactically correct, then it will assemble without any output -- no news is good news. If there is an error in the code, however, you will see one of two kinds of errors:

  1. An error is the number or type of the operands: This kind of error will cause a specific (and somewhat descriptive) error message to be emitted, and the assembly process to terminate, returning you to the shell.

  2. Any other error: All other errors (invalid opcodes, unknown register specifiers, unknown label names, etc.) will result in a more crytpic error message to be emitted. You will be left within the Scheme interpreter, at a single greater-than (>) prompt. The following will allow you to return to the shell:

    (exit)

    While future versions of the assembler may provide more helpful error messages in these cases. Meanwhile, I hope that the error messages provide some clue as to the error.

Be sure to follow the format of the assembly code (particularly the use of parentheses) described above on this page. Errors in this format may cause some of the most cryptic errors.


Scott F. Kaplan
Last modified: Sun Sep 11 21:45:29 EDT 2005