gumnut_assembler.assembler

Module Contents

Classes

GumnutAssembler

GasmLine

GasmInstruction

Functions

main()

Attributes

logger

gumnut_assembler.assembler.logger
class gumnut_assembler.assembler.GumnutAssembler
load_asm_source_from_file(self, filename)

Load assembler source from file and split each line into a list

Parameters

filename – Path to source file

load_asm_source(self, source)

Load assembler source from string and split each line into a list

Parameters

source – Source code as a string

assemble(self)
_check_number(self, operand)

Check operand for number format and return number as base 10 otherwise return original operand

Parameters

operand – The number to check as a string. 0xDE, 0b0110, 12

Returns

The number as a integer with base 10 if the input was a valid number string. Otherwise -1

Todo

Refactor two’s complement conversion

_format_input(self, operand)

Format the parsed inputs by removing any whitespace

_extract_identifier_from_line(self, asm_source)

Extract identifiers from assembly source line via regex

Parameters

asm_source – A string containing a single line of asm code.

Returns

A GasmLine Object containing the extracted data. False if there was no match.

Todo

Add support for ascii chars e.g.: char_a: equ ‘a’

_parse_asm_source(self)

Loop through each line of raw assembler source and generate a list of GasmLines.

_check_if_immed_instr(self, operand)

Check if the passed operand is suitable for a immediate instruction. To do this check if passed operand is a register/reference or a number.

Parameters

operand – A string to check for register/reference.

Returns

True if operand is a number or reference False if operand is register or invalid

_get_register_number(self, operand)

Extract the register number from operand string

Parameters

operand – A string from which to get the register number

Returns

integer if operand is a number -1 if operand is no valid number

_get_reference_or_value(self, operand)
_check_operand_for_reference(self, operand)

Check if operand is a valid reference

_get_reference(self, reference)

Get a reference’s value

_clear_memory(self)

Clear both memory lists and set each cell to 0

_assemble_source_line(self, asm_line)

Assemble a single code line

_iterate(self)

Loop one time through all source lines and assemble object code.

create_output_files(self, datafile='gasm_data.dat', textfile='gasm_text.dat')

Create output files

get_instruction_memory(self)

Return instruction memory as a list.

get_data_memory(self)

Return data memory as a list

print_source_objcode_map(self)
_validate_asm_line(self, asm_line)
class gumnut_assembler.assembler.GasmLine(label=None, instruction=None, rd=None, op1=None, op2=None)
__eq__(self, other)

Return self==value.

is_empty(self)
__str__(self)

Return str(self).

__repr__(self)

Return repr(self).

class gumnut_assembler.assembler.GasmInstruction(instruction=None, rd=False, op1=False, op2=False)
gumnut_assembler.assembler.main()