Skip to content

A modular general 2-pass assembler written in Python.

License

Notifications You must be signed in to change notification settings

GodTamIt/assembler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assembler

A general 2-pass assembler with implementations of LC-2200 and LC3-2200a.

Requirements

The assembler runs on any version of Python 2.6+. An instruction set architecture definition file is required along with the assembler. In this repository, several sample ISA definitions have been provided (see below).

Sample Definitions

Options

The assembler contains multiple options.

python assembler.py -h prints:

usage: Assembles generic ISA-defined assembly code into hex or binary.
       [-h] [-i ISA] [-v] [--hex] [-s SEPARATOR] [--sym] [--params PARAMS]
       asmfile

positional arguments:
  asmfile               the .s file to be assembled

optional arguments:
  -h, --help            show this help message and exit
  -i ISA, --isa ISA     define the Python ISA module to load [default: isa]
  -v, --verbose         enable verbose printing of assembler
  --hex, --logisim      assemble code into hexadecimal (Logisim-compatible)
  -s SEPARATOR, --separator SEPARATOR
                        the separator to use between instructions (accepts \s
                        for space and standard escape characters) [default:
                        \n]
  --sym, --symbols      output an additional file containing the assembled
                        program's symbol table
  --params PARAMS       custom parameters to pass to an architecture,
                        formatted as "key1=value1, key2=value2, key3=value3"

How to Use

Typical usage:

./assembler.py <assembly_file> -i <isa_definition>

Example usage with the lc2200.py definition:

./assembler.py assembly.s -i lc2200

To output assembled code in hexadecimal (compatible with Logisim images):

./assembler.py assembly.s -i lc2200 --logisim

To separate entries by a space:

./assembler.py assembly.s -i lc2200 --separator \s