Tools

Basic Assembler

py_register_machine2.tools.assembler.assember: The Basic Assembler

Just replaces mnemonics with opcodes and handles references.

exception py_register_machine2.tools.assembler.assembler.ArgumentError(*args)[source]

Raised if an argument does not fit the requirements.

exception py_register_machine2.tools.assembler.assembler.AssembleError(*args)[source]

Rasied if the assemler terminates without success.

class py_register_machine2.tools.assembler.assembler.Assembler(processor, open_stream, directives=[], commentstarts=[';'])[source]

Reads assembly code from open_stream and converts it to a list of integers that can be programmed to the ROM or the Flash.

Stages:

Split Run
Reads the complete file and converts it to a list of tuples: [(lineno, "command", <command>, arguments), ...]` or [(lineno, "data", <data description>, data), ...]`
Argument Run
Checks and converts the arguments. Unconvertable str objects are interpreted as addresses.
Dereference Run
Handles references.
Program Run
Generates one iterable of integers
add_ref(wordlist)[source]

Adds a reference.

argument_run(sp_r)[source]

Converts Arguments according to to_int

assemble()[source]

Chains split_run, argument_run, dereference_run and program_run.

checkargs(lineno, command, args)[source]

Check if the arguments fit the requirements of the command.

Raises ArgumentError, if an argument does not fit.

convert_args(command, args)[source]

Converts str -> int or register -> int.

dereference_run(arg_r)[source]

Converts the commands to opcodes and inserts the (relative or static) references.

getdirective(name)[source]

Returns the directive with the name name.

handle_directive(words)[source]

handles directives: adds the reference and allocates space for the content

isdirective(words)[source]

Check if the line words is a directive.

program_run(der_r)[source]

Generates an iterable that can be programmed onto the register machine.

split_run()[source]

Splits the assembly code into

  • commands
  • directives
  • jump marks
py_register_machine2.tools.assembler.assembler.isreference(wordlist)[source]

if the line is a reference (jump mark), return true

Assembly Directives

class py_register_machine2.tools.assembler.directives.BaseDirective(name)[source]

Every Directive has to provide the following Attributes/Methods:

  • name (like .set)
  • get_words(line): return the data to store
  • get_word_count(line): return the number of words to store
  • isstatic() returns True, if the reference should be static
class py_register_machine2.tools.assembler.directives.ConvertingDirective(name, function)[source]

The function function will have to take the rest of the line (as a list) and convert it to an iterable of int objects

Example: The .string directive:

# usage: .string name string
# ie.: .string foo this is a test

def string_function(line):
        line = " ".join(line)
        res = []
        for char in line:
                res.append(ord(char))
        return res
class py_register_machine2.tools.assembler.directives.Padding(name='.padd')[source]

Usage:

.padd name n v

Fills the next n words with v.

class py_register_machine2.tools.assembler.directives.Zeros(name='.zeros')[source]

Usage:

.zeros name n   

Fills the next n words with zeros.