tools.assembler
Class Assembler

java.lang.Object
  extended by tools.assembler.Assembler

public class Assembler
extends java.lang.Object

This application reads a text file (with includes) into a list of CodeLines and assembles the code lines to give them data and addresses. Many of the assembly steps are static methods that can be reused in other contexts.


Constructor Summary
Assembler()
           
 
Method Summary
static CodeLine assemble(java.util.List<CodeLine> codeLines, java.util.Map<java.lang.String,java.lang.String> defines, java.util.Map<java.lang.String,AddressSpec> addresses, java.util.Set<java.lang.String> usedBlendLabels)
          This function performs the assembly of the given code lines.
static int[] extractBinary(java.util.List<CodeLine> codeLines, int start, int end)
           
static void main(java.lang.String[] args)
          This tool assembles a text file into a binary file and produces an optional listing file.
static void printListing(java.io.PrintStream ps, java.util.List<CodeLine> codeLines, java.util.Map<java.lang.String,java.lang.String> defines, java.util.Map<java.lang.String,AddressSpec> addresses, java.util.Set<java.lang.String> usedBlendLabels)
           
static java.util.List<CodeLine> readAssemblyText(java.lang.String name)
          This function reads an assembly file (and includes) and parses it into CodeLines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assembler

public Assembler()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
This tool assembles a text file into a binary file and produces an optional listing file. Command line arguments: inputFileName outputFileName [-list] Files may be included (recursively) in the input file with the following syntax: include myFile.asm The exact syntax of the individual mnemonics depends on the target CPU's mnemonic set. But there is some common structure for all assembly files: The colon ':' is reserved to mark the end of a label. A line may have have only one label. Labels collapse down to the first line of generated data. Origins are labels that happen to be numeric. All numeric constants may have an optional base specification. The default base is decimal. Examples of numbers: "0xFF00" and "123" and "0b00_11_11_00". Note that '_' are ignored in numeric constants but may be used to separate fields. Values may be defined with a "define" directive: define key = value Memory address outside the code area may be defined with an "address" directive. Memory addresses can be assigned automatically in increasing order using a "*". address mySpot = 0xF000 byte ; mySpot points to a byte at F000 address myOtherSpot = * word ; myOtherSpot points to F001 address baseSpot = >0x80 byte ; The ">" means an 8-bit address (base/zero page) address bs2 = * ; bs2 points to 81 and is a byte The program must define 'CPU' before the first opcode. Like: define CPU = 8080 or define CPU = 8080 as Z80,Cish The "as" clause narrows the mnemonics to just the list given. If "as" is not given then the instruction set is the processor and the "Cish" set. A line beginning with '#' is parsed as data. For example: # 1,2,3,(WORD)4,5,(BYTE)6,20,PF0,"This is a test",0 Once WORD or BYTE is given on a line the following data is the same size unless overridden.

Parameters:
args - the command line arguments
Throws:
java.lang.Exception - if anything goes wrong

assemble

public static CodeLine assemble(java.util.List<CodeLine> codeLines,
                                java.util.Map<java.lang.String,java.lang.String> defines,
                                java.util.Map<java.lang.String,AddressSpec> addresses,
                                java.util.Set<java.lang.String> usedBlendLabels)
This function performs the assembly of the given code lines. Each line is filled out with an address and data.

Parameters:
codeLines - the list of lines
Returns:
any error or null if OK

readAssemblyText

public static java.util.List<CodeLine> readAssemblyText(java.lang.String name)
                                                 throws java.io.IOException
This function reads an assembly file (and includes) and parses it into CodeLines.

Parameters:
name - the name of the file
Returns:
the list of code lines
Throws:
java.io.IOException - with file errors

extractBinary

public static int[] extractBinary(java.util.List<CodeLine> codeLines,
                                  int start,
                                  int end)

printListing

public static void printListing(java.io.PrintStream ps,
                                java.util.List<CodeLine> codeLines,
                                java.util.Map<java.lang.String,java.lang.String> defines,
                                java.util.Map<java.lang.String,AddressSpec> addresses,
                                java.util.Set<java.lang.String> usedBlendLabels)