comp
Class Assembler

java.lang.Object
  |
  +--comp.Assembler

public class Assembler
extends java.lang.Object

An object that knows how to spit out (MIPS) assembly code. Should really be an interface, with a MIPS implementation, but that's taking things a little far right now.

Version:
$Id: Assembler.java,v 1.6 2002/05/10 22:49:25 dugan Exp $

Field Summary
static int ADD
          Binary operators.
static int AND
           
static int DIV
           
static int EQ
           
static int GT
           
static int GTE
           
static int LT
           
static int LTE
           
static int MOD
           
static int MULT
           
static int NEQ
           
static int OR
           
(package private) static java.io.PrintStream out
           
static int SLL
           
static int SRA
           
static int SRL
           
static int SUB
           
static int XOR
           
 
Constructor Summary
Assembler()
           
 
Method Summary
 void addImm(java.lang.String dest, java.lang.String reg, int imm)
          Add the immediate operand to reg, and place the result in dest.
 void binop(int op, java.lang.String dest, java.lang.String left, java.lang.String right)
          Emit a binary operation on the three given registers.
 void branchEq(java.lang.String r1, java.lang.String r2, java.lang.String label)
          Branch to the given label if regs[r1] == regs[r2]
 void branchNe(java.lang.String r1, java.lang.String r2, java.lang.String label)
          Branch to the given label if regs[r1] != regs[r2]
 void call(java.lang.String label)
          Call the procedure.
 void comment(java.lang.String msg)
          Issue a comment without newline.
 void commentln(java.lang.String msg)
          Issue a comment on a line by itself.
 void dumpStrings(java.util.Map strings)
          Dump a Map of static strings to the text region.
 void growStack(int bytes)
          Grow the stack by the given number of bytes.
 void jump(java.lang.String label)
          Unconditionally jump to the given label.
 void jumpReg(java.lang.String reg)
          Jump to the address in the register.
 void label(java.lang.String label)
          Issue a label, without a trailing newline.
 void labelln(java.lang.String label)
          Issue a label on its own line.
 void loadAddress(java.lang.String dest, java.lang.String label)
          Load an address.
 void loadByte(java.lang.String dest, int offset, java.lang.String base)
          Load a byte from the integer offset of base register into the dest.
 void loadByte(java.lang.String dest, java.lang.String label, java.lang.String base)
          Load a byte from the labeled offset of base register.
 void loadImm(java.lang.String dest, int imm)
          Handles constants larger than |2^15| now
 void loadWord(java.lang.String dest, int offset, java.lang.String base)
          Load a word from offset of base register into the dest register.
 void loadWord(java.lang.String dest, java.lang.String label, java.lang.String base)
          Load a word from the labeled offset of base register into the dest.
 void move(java.lang.String dest, java.lang.String src)
          Move the value in the src register into the dest register.
 void nop()
          Do nothing.
 void shrinkStack(int bytes)
          Shrink the stack by the given number of bytes.
 void space(java.lang.String label, int size)
          Ask for size bytes of space.
 void startData()
          Start the dtaa section.
 void startText()
          Start the text section.
 void storeByte(java.lang.String src, int offset, java.lang.String base)
          Store a byte to the integer offset of base register.
 void storeByte(java.lang.String src, java.lang.String label, java.lang.String base)
          Store a byte to the labeled offset of base register
 void storeWord(java.lang.String src, int offset, java.lang.String base)
          Store a word from offset of base register into the dest register.
 void storeWord(java.lang.String src, java.lang.String label, java.lang.String base)
          Store a word into the labeled offset of base register
 void word(java.lang.String label, int value)
          Ask for a word size of space with the intial value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

static java.io.PrintStream out

ADD

public static final int ADD
Binary operators.

See Also:
Constant Field Values

SUB

public static final int SUB
See Also:
Constant Field Values

MOD

public static final int MOD
See Also:
Constant Field Values

MULT

public static final int MULT
See Also:
Constant Field Values

DIV

public static final int DIV
See Also:
Constant Field Values

EQ

public static final int EQ
See Also:
Constant Field Values

NEQ

public static final int NEQ
See Also:
Constant Field Values

LT

public static final int LT
See Also:
Constant Field Values

GT

public static final int GT
See Also:
Constant Field Values

LTE

public static final int LTE
See Also:
Constant Field Values

GTE

public static final int GTE
See Also:
Constant Field Values

SLL

public static final int SLL
See Also:
Constant Field Values

SRL

public static final int SRL
See Also:
Constant Field Values

SRA

public static final int SRA
See Also:
Constant Field Values

AND

public static final int AND
See Also:
Constant Field Values

OR

public static final int OR
See Also:
Constant Field Values

XOR

public static final int XOR
See Also:
Constant Field Values
Constructor Detail

Assembler

public Assembler()
Method Detail

commentln

public void commentln(java.lang.String msg)
Issue a comment on a line by itself.


comment

public void comment(java.lang.String msg)
Issue a comment without newline.


label

public void label(java.lang.String label)
Issue a label, without a trailing newline.


labelln

public void labelln(java.lang.String label)
Issue a label on its own line.


dumpStrings

public void dumpStrings(java.util.Map strings)
Dump a Map of static strings to the text region. The map should map labels -> strings.


space

public void space(java.lang.String label,
                  int size)
Ask for size bytes of space.


word

public void word(java.lang.String label,
                 int value)
Ask for a word size of space with the intial value.


startData

public void startData()
Start the dtaa section.


startText

public void startText()
Start the text section.


binop

public void binop(int op,
                  java.lang.String dest,
                  java.lang.String left,
                  java.lang.String right)
Emit a binary operation on the three given registers.


addImm

public void addImm(java.lang.String dest,
                   java.lang.String reg,
                   int imm)
Add the immediate operand to reg, and place the result in dest.


loadWord

public void loadWord(java.lang.String dest,
                     int offset,
                     java.lang.String base)
Load a word from offset of base register into the dest register.


loadWord

public void loadWord(java.lang.String dest,
                     java.lang.String label,
                     java.lang.String base)
Load a word from the labeled offset of base register into the dest.


storeWord

public void storeWord(java.lang.String src,
                      int offset,
                      java.lang.String base)
Store a word from offset of base register into the dest register.


storeWord

public void storeWord(java.lang.String src,
                      java.lang.String label,
                      java.lang.String base)
Store a word into the labeled offset of base register


loadByte

public void loadByte(java.lang.String dest,
                     int offset,
                     java.lang.String base)
Load a byte from the integer offset of base register into the dest.


loadByte

public void loadByte(java.lang.String dest,
                     java.lang.String label,
                     java.lang.String base)
Load a byte from the labeled offset of base register.


storeByte

public void storeByte(java.lang.String src,
                      int offset,
                      java.lang.String base)
Store a byte to the integer offset of base register.


storeByte

public void storeByte(java.lang.String src,
                      java.lang.String label,
                      java.lang.String base)
Store a byte to the labeled offset of base register


loadImm

public void loadImm(java.lang.String dest,
                    int imm)
Handles constants larger than |2^15| now


loadAddress

public void loadAddress(java.lang.String dest,
                        java.lang.String label)
Load an address. This is a weird pseudo-op at this level. The label should be label defined in the data segment.


growStack

public void growStack(int bytes)
Grow the stack by the given number of bytes.


shrinkStack

public void shrinkStack(int bytes)
Shrink the stack by the given number of bytes.


move

public void move(java.lang.String dest,
                 java.lang.String src)
Move the value in the src register into the dest register.


branchEq

public void branchEq(java.lang.String r1,
                     java.lang.String r2,
                     java.lang.String label)
Branch to the given label if regs[r1] == regs[r2]


branchNe

public void branchNe(java.lang.String r1,
                     java.lang.String r2,
                     java.lang.String label)
Branch to the given label if regs[r1] != regs[r2]


jump

public void jump(java.lang.String label)
Unconditionally jump to the given label.


jumpReg

public void jumpReg(java.lang.String reg)
Jump to the address in the register.


call

public void call(java.lang.String label)
Call the procedure. Save the return address.


nop

public void nop()
Do nothing.