hades.models.pic
Class PicAssembler

java.lang.Object
  extended byhades.models.pic.PicAssembler

public class PicAssembler
extends java.lang.Object

A simple assembler for the Arizona Microchip PIC16CXX family of 8-bit microcontrollers. The current version supports:

All in all, this assembler should 'look and feel' more or less like MPASM 2.3, except for the following features:

The symbol table is realized with two Hashtables. The first Hashtable maps symbol (label, opcode, ...) names into values. The second Hashtable maps symbol names into symbol types like T_UNDEFINED, T_OPOCDE, T_LABEL, etc.


Field Summary
(package private)  int current_addr
           
(package private)  int[] instructionMemory
           
(package private)  java.util.Hashtable labelTargetTable
           
(package private)  int max_addr
           
(package private)  java.util.Hashtable opcodeArgsTable
           
(package private)  java.util.Vector patchAddressVector
           
(package private)  java.util.Vector patchLabelVector
           
(package private)  java.util.Vector rawTokens
           
(package private)  java.lang.String sourcefilename
           
(package private)  java.util.Hashtable symbolTable
           
(package private)  java.util.Hashtable symbolTypeTable
           
static int T_EQU
           
static int T_INCLUDE
           
static int T_LABEL
           
static int T_LIST
           
static int T_OPCODE
           
static int T_ORG
           
static int T_SHORTHAND
           
static int T_UNDEFINED
           
static int T_UNKNOWN
           
 
Constructor Summary
PicAssembler()
           
 
Method Summary
 void addOpcodeSymbol(java.lang.String key, java.lang.String value, int n_args)
          call addSymbol with both the String key and a second time with the uppercase-version of key
 void addStandaloneLabel(java.lang.String[] tokens)
          we just found a Label definition sitting alone on one line.
 void addSymbol(java.lang.String key, java.lang.Object value, int type)
          create a new symbol table entry for key with value.
 void addSymbol2(java.lang.String key, java.lang.Object value, int type)
          call addSymbol with both the String key and a second time with the uppercase-version of key
 void codegen()
           
 void copyright()
           
 void createPic16C84RegisterNameSymbols()
           
 void createPic16xxOpcodeSymbols()
           
 void createPicInstructionMemory()
           
 void createPicMetaSymbols()
           
 void createSymbolTable()
           
 void defineLabel(java.lang.String label, int address)
          try to define a Label Symbol with the Label's target address.
 void dumpRawTokens(java.util.Vector rawTokens)
           
 void dumpSymbolTable(java.io.PrintStream ps)
           
 java.lang.String flushLeft(java.lang.Object o, int fieldsize)
           
 java.lang.String getFilename()
           
 int getLabelAddress(java.lang.String label)
           
 int getMemorySize()
           
 int getNOP()
           
 java.io.PrintWriter getPrintWriter(java.lang.String suffix)
           
 void getReader()
           
 java.lang.String getSymbol(java.lang.String key)
           
 int getSymbolType(java.lang.String key)
           
 void handleEquExpression(java.lang.String[] tokens)
           
 void handleIncludeExpression(java.lang.String[] tokens)
           
 void handleLabelAndOpcode(java.lang.String[] tokens)
           
 void handleListExpression(java.lang.String[] tokens)
           
 void handleOpcode(java.lang.String[] tokens)
           
 void handleOrgExpression(java.lang.String[] tokens)
           
 boolean isEquSymbol(java.lang.String key)
           
 boolean isOpcodeSymbol(java.lang.String key)
           
 boolean isSymbol(java.lang.String key)
           
static void main(java.lang.String[] argv)
           
static void msg(java.lang.String s)
           
 void parse(java.io.BufferedReader reader)
           
 int parseNumber(java.lang.String s)
          try to parse an integer from a string in one of the following reps: [0-9]+ normal decimal number 0b[01]+ binary number 0d[0-9]+ decimal number 0x[0-F]+ hex number b'[01]+' binary number d'[0-9]+' decimal number x'[0-f]+' hex number '[ascii-char]' ascii char .[0-9]+ decimal number [0-f]+h hex number
 void patchLabels()
           
 void printLineTokens(java.lang.String[] tokens)
           
 java.lang.String printSymbolType(java.lang.String key)
           
 void setFilename(java.lang.String sourcefilename)
           
 void setOptions(java.lang.String[] argv)
           
 java.lang.String stripComments(java.lang.String line)
           
 void tokenize(java.io.BufferedReader reader)
           
 java.lang.String[] tokenizeLine(java.lang.String line)
           
 void usage()
           
 void writeHex(java.io.PrintWriter writer)
           
 void writeLabels(java.io.PrintWriter writer)
           
 void writeRawLabels(java.io.PrintWriter writer)
           
 void writeRom(java.io.PrintWriter writer)
           
 void writeSymbolTable(java.io.PrintWriter writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbolTable

java.util.Hashtable symbolTable

symbolTypeTable

java.util.Hashtable symbolTypeTable

opcodeArgsTable

java.util.Hashtable opcodeArgsTable

rawTokens

java.util.Vector rawTokens

instructionMemory

int[] instructionMemory

labelTargetTable

java.util.Hashtable labelTargetTable

patchAddressVector

java.util.Vector patchAddressVector

patchLabelVector

java.util.Vector patchLabelVector

current_addr

int current_addr

max_addr

int max_addr

sourcefilename

java.lang.String sourcefilename

T_UNDEFINED

public static final int T_UNDEFINED
See Also:
Constant Field Values

T_UNKNOWN

public static final int T_UNKNOWN
See Also:
Constant Field Values

T_OPCODE

public static final int T_OPCODE
See Also:
Constant Field Values

T_ORG

public static final int T_ORG
See Also:
Constant Field Values

T_EQU

public static final int T_EQU
See Also:
Constant Field Values

T_LABEL

public static final int T_LABEL
See Also:
Constant Field Values

T_SHORTHAND

public static final int T_SHORTHAND
See Also:
Constant Field Values

T_INCLUDE

public static final int T_INCLUDE
See Also:
Constant Field Values

T_LIST

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

PicAssembler

public PicAssembler()
Method Detail

getMemorySize

public int getMemorySize()

getNOP

public int getNOP()

createPicInstructionMemory

public void createPicInstructionMemory()

createSymbolTable

public void createSymbolTable()

createPicMetaSymbols

public void createPicMetaSymbols()

createPic16xxOpcodeSymbols

public void createPic16xxOpcodeSymbols()

createPic16C84RegisterNameSymbols

public void createPic16C84RegisterNameSymbols()

addSymbol

public void addSymbol(java.lang.String key,
                      java.lang.Object value,
                      int type)
               throws java.lang.Exception
create a new symbol table entry for key with value. To prevent multiple symbol definitions (which are illegal), we throw an Exception when a symbol is defined for the second time. Use changeSymbol

Throws:
java.lang.Exception

addSymbol2

public void addSymbol2(java.lang.String key,
                       java.lang.Object value,
                       int type)
                throws java.lang.Exception
call addSymbol with both the String key and a second time with the uppercase-version of key

Throws:
java.lang.Exception

addOpcodeSymbol

public void addOpcodeSymbol(java.lang.String key,
                            java.lang.String value,
                            int n_args)
                     throws java.lang.Exception
call addSymbol with both the String key and a second time with the uppercase-version of key

Throws:
java.lang.Exception

getSymbolType

public int getSymbolType(java.lang.String key)

isOpcodeSymbol

public boolean isOpcodeSymbol(java.lang.String key)

isEquSymbol

public boolean isEquSymbol(java.lang.String key)

isSymbol

public boolean isSymbol(java.lang.String key)

getSymbol

public java.lang.String getSymbol(java.lang.String key)

printSymbolType

public java.lang.String printSymbolType(java.lang.String key)

dumpSymbolTable

public void dumpSymbolTable(java.io.PrintStream ps)

defineLabel

public void defineLabel(java.lang.String label,
                        int address)
                 throws java.lang.Exception
try to define a Label Symbol with the Label's target address. This will work only if either the label was never defined before, or if it was defined with type T_UNKNOWN or T_UNDEFINED

Throws:
java.lang.Exception

getLabelAddress

public int getLabelAddress(java.lang.String label)
                    throws java.lang.Exception
Throws:
java.lang.Exception

parse

public void parse(java.io.BufferedReader reader)

writeRom

public void writeRom(java.io.PrintWriter writer)
              throws java.lang.Exception
Throws:
java.lang.Exception

writeHex

public void writeHex(java.io.PrintWriter writer)
              throws java.lang.Exception
Throws:
java.lang.Exception

writeLabels

public void writeLabels(java.io.PrintWriter writer)
                 throws java.lang.Exception
Throws:
java.lang.Exception

writeRawLabels

public void writeRawLabels(java.io.PrintWriter writer)
                    throws java.lang.Exception
Throws:
java.lang.Exception

writeSymbolTable

public void writeSymbolTable(java.io.PrintWriter writer)
                      throws java.lang.Exception
Throws:
java.lang.Exception

flushLeft

public java.lang.String flushLeft(java.lang.Object o,
                                  int fieldsize)

patchLabels

public void patchLabels()

codegen

public void codegen()

addStandaloneLabel

public void addStandaloneLabel(java.lang.String[] tokens)
                        throws java.lang.Exception
we just found a Label definition sitting alone on one line. Add the label to our symbol table, and both the label and the current instruction address to the labelTargetTable.

Throws:
java.lang.Exception

handleOpcode

public void handleOpcode(java.lang.String[] tokens)
                  throws java.lang.Exception
Throws:
java.lang.Exception

handleLabelAndOpcode

public void handleLabelAndOpcode(java.lang.String[] tokens)
                          throws java.lang.Exception
Throws:
java.lang.Exception

handleListExpression

public void handleListExpression(java.lang.String[] tokens)
                          throws java.lang.Exception
Throws:
java.lang.Exception

handleIncludeExpression

public void handleIncludeExpression(java.lang.String[] tokens)
                             throws java.lang.Exception
Throws:
java.lang.Exception

handleOrgExpression

public void handleOrgExpression(java.lang.String[] tokens)
                         throws java.lang.Exception
Throws:
java.lang.Exception

handleEquExpression

public void handleEquExpression(java.lang.String[] tokens)
                         throws java.lang.Exception
Throws:
java.lang.Exception

tokenize

public void tokenize(java.io.BufferedReader reader)

dumpRawTokens

public void dumpRawTokens(java.util.Vector rawTokens)

tokenizeLine

public java.lang.String[] tokenizeLine(java.lang.String line)

printLineTokens

public void printLineTokens(java.lang.String[] tokens)

stripComments

public java.lang.String stripComments(java.lang.String line)

parseNumber

public int parseNumber(java.lang.String s)
try to parse an integer from a string in one of the following reps: [0-9]+ normal decimal number 0b[01]+ binary number 0d[0-9]+ decimal number 0x[0-F]+ hex number b'[01]+' binary number d'[0-9]+' decimal number x'[0-f]+' hex number '[ascii-char]' ascii char .[0-9]+ decimal number [0-f]+h hex number


setOptions

public void setOptions(java.lang.String[] argv)

setFilename

public void setFilename(java.lang.String sourcefilename)

getFilename

public java.lang.String getFilename()

getReader

public void getReader()

getPrintWriter

public java.io.PrintWriter getPrintWriter(java.lang.String suffix)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

usage

public void usage()

copyright

public void copyright()

msg

public static void msg(java.lang.String s)

main

public static void main(java.lang.String[] argv)