DASM
|
DASM DCPU-16 source assembler class. More...
Private Member Functions | |
Public Functions | |
retval | new (scalar proto, scalar dasm) |
Create an object upon which we can work. | |
retval | identify (scalar self, scalar filename, scalar type) |
Identify whether we can handle reading or writing a given file by its filename. | |
retval | extensions () |
List the extensions we support. | |
retval | parseline (scalar self, scalar line) |
Parse an instruction line. | |
retval | rebindregister (scalar self, scalar new, scalar old) |
Bind register names, to give them other names than the default. | |
retval | regbinding (scalar self, scalar reg) |
Map a register name to a standard register name. | |
retval | op_DAT (scalar self, scalar lineref, scalar labelref) |
Special opcode 'DAT' to define data in the core. | |
retval | op_RES (scalar self, scalar lineref, scalar labelref) |
Special opcode 'RES' to reserve a block of memory in the core. | |
retval | op_CONST (scalar self, scalar lineref, scalar labelref) |
Special opcode 'CONST' to define a constant symbol. | |
retval | op_ADDRESS (scalar self, scalar lineref, scalar labelref) |
Special opcode 'ADDRESS' to define an address symbol. | |
retval | op_RN (scalar self, scalar lineref, scalar labelref) |
Special opcode 'RN' to define a register name (binding) | |
retval | directive_ORIGIN (scalar self, scalar lineref) |
Assembler directive 'ORIGIN' to change compilation address. | |
retval | directive_INCLUDE (scalar self, scalar lineref) |
Assembler directive 'ORIGIN' to change compilation address. | |
retval | parse_operand (scalar self, scalar lineref, scalar wrap) |
Parse operands and return the values of them. | |
retval | parse_symbol (scalar self, scalar lineref, scalar nonterm) |
Parse a symbol name or value. | |
retval | parse_constant (scalar self, scalar lineref, scalar symbol, scalar wrap) |
Obtain a constant from an input line. | |
retval | write (scalar self) |
Write out a compilable source file based on what we have in the core. | |
retval | decode_operand (scalar self, scalar operand, scalar address, scalar memdataref) |
Decode an operand into a string. | |
retval | decode_nextword (scalar self, scalar address, scalar memdataref) |
Read the next word from a memory address, whilst decoding operands. | |
Private Attributes | |
scalar | debug_dat |
Whether we're debugging the 'DAT' instruction. | |
scalar | debug_sym |
Whether we're debugging the symbol processing. | |
scalar | disassemble_res_limit |
How much we reserve in our disassembly before changing to .ORIGIN. |
DASM DCPU-16 source assembler class.
This class provides the implementation of the source code assembler for DASM.
The files we support end in '.dasm'.
Source file format:
[<label>] <opcode> <operand a>, <operand b> [<label>] <ext-opcode> <operand> ; <comment>
It also provides a disassembler which can produce source code which can be passed back to the assembler. If the source comes from one of the binary formats that doesn't offer relocations or symblols, the content will be more difficult to parse interpret, but should still work.
The structures we use are intended to be able to support libraries of relocatable, partially linked code. This has not yet been tested and the lack of any indication of which symbols are local and which are imported may be a problem in the future.
In addition to the 1.1 DCPU-16 specification, the assembler supports:
'X'
will evaluate to the number 88.1+4
will evaluate to the number 5. data + 4
will evaluate to the value of symbol 'data
' plus 4. $
' character: $
' will have the last label used prepended to the symbol name. This allows labels and references to be used within a routine without polluting the global namespace.DAT <value[,<value> ]*
RES <value>
CONST value
ADDRESS <value>
RN <register>
.<directive> <parameters>
allows additional meta operations to be performed. Directives supported:.ORIGIN address
.INCLUDE file
retval DASMIO::Source::decode_nextword | ( | scalar | self, |
scalar | address, | ||
scalar | memdataref | ||
) | [private] |
Read the next word from a memory address, whilst decoding operands.
Apply any relocations that we know about such that the decode comes out as readable.
The actual value in memory is appended to the memdataref list. If the memory is not known, we return '?' and an undef entry in the array.
[in] | $self | IO object |
[in] | $address | Address of 'nextword' |
[in,out] | $memdataref | Reference to an address of data read from memory which we will update if we read any data |
retval DASMIO::Source::decode_operand | ( | scalar | self, |
scalar | operand, | ||
scalar | address, | ||
scalar | memdataref | ||
) | [private] |
Decode an operand into a string.
[in] | $self | IO object |
[in] | $operand | Operand value |
[in] | $address | Address of 'nextword' |
[in,out] | $memdataref | Reference to an address of data read from memory which we will update if we read any data |
retval DASMIO::Source::directive_INCLUDE | ( | scalar | self, |
scalar | lineref | ||
) | [private] |
Assembler directive 'ORIGIN' to change compilation address.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
retval DASMIO::Source::directive_ORIGIN | ( | scalar | self, |
scalar | lineref | ||
) | [private] |
Assembler directive 'ORIGIN' to change compilation address.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
retval DASMIO::Source::extensions | ( | ) | [private] |
List the extensions we support.
[in] | $self | Our object |
retval DASMIO::Source::identify | ( | scalar | self, |
scalar | filename, | ||
scalar | type | ||
) | [private] |
Identify whether we can handle reading or writing a given file by its filename.
[in] | $self | Our object |
[in] | $filename | Filename we're accessing |
[in] | $type | 'read' or 'write' |
1 | if we can access it |
0 | if we cannot access it |
retval DASMIO::Source::new | ( | scalar | proto, |
scalar | dasm | ||
) | [private] |
Create an object upon which we can work.
[in] | $proto | Prototype object, or this class's name |
[in] | $dasm | DASM object we're working on |
retval DASMIO::Source::op_ADDRESS | ( | scalar | self, |
scalar | lineref, | ||
scalar | labelref | ||
) | [private] |
Special opcode 'ADDRESS' to define an address symbol.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
[in,out] | $labelref | Reference to the label for this line, updated to undef if we should not defined a label for this initial address |
retval DASMIO::Source::op_CONST | ( | scalar | self, |
scalar | lineref, | ||
scalar | labelref | ||
) | [private] |
Special opcode 'CONST' to define a constant symbol.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
[in,out] | $labelref | Reference to the label for this line, updated to undef if we should not defined a label for this initial address |
retval DASMIO::Source::op_DAT | ( | scalar | self, |
scalar | lineref, | ||
scalar | labelref | ||
) | [private] |
Special opcode 'DAT' to define data in the core.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
[in,out] | $labelref | Reference to the label for this line, updated to undef if we should not defined a label for this initial address |
retval DASMIO::Source::op_RES | ( | scalar | self, |
scalar | lineref, | ||
scalar | labelref | ||
) | [private] |
Special opcode 'RES' to reserve a block of memory in the core.
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
[in,out] | $labelref | Reference to the label for this line, updated to undef if we should not defined a label for this initial address |
retval DASMIO::Source::op_RN | ( | scalar | self, |
scalar | lineref, | ||
scalar | labelref | ||
) | [private] |
Special opcode 'RN' to define a register name (binding)
[in] | $self | This source object |
[in,out] | $lineref | Reference to the line end we are parsing, updated to leave remaining text |
[in,out] | $labelref | Reference to the label for this line, updated to undef if we should not defined a label for this initial address |
retval DASMIO::Source::parse_constant | ( | scalar | self, |
scalar | lineref, | ||
scalar | symbol, | ||
scalar | wrap | ||
) | [private] |
Obtain a constant from an input line.
[in] | $self | DASMIO object |
[in,out] | $lineref | reference to line to read from |
[in] | $symbol | 'constant' : only a constant is acceptable 'symbol' : symbol is acceptable (default) |
[in] | $wrap | 'nowrap' : do not wrap large/small numbers 'wrap' : wrap numbers (default) |
retval DASMIO::Source::parse_operand | ( | scalar | self, |
scalar | lineref, | ||
scalar | wrap | ||
) | [private] |
Parse operands and return the values of them.
[in] | $self | IO object |
[in,out] | $lineref | Reference to the line that we're parsing |
[in] | $wrap | 'nowrap' : do not wrap large/small numbers 'wrap' : wrap numbers (default) |
retval DASMIO::Source::parse_symbol | ( | scalar | self, |
scalar | lineref, | ||
scalar | nonterm | ||
) | [private] |
Parse a symbol name or value.
[in] | $self | DASM object |
[in,out] | $lineref | Reference to the line that we're parsing |
retval DASMIO::Source::parseline | ( | scalar | self, |
scalar | line | ||
) | [private] |
Parse an instruction line.
[in] | $self | IO object |
[in] | $line | Line to process |
retval DASMIO::Source::rebindregister | ( | scalar | self, |
scalar | new, | ||
scalar | old | ||
) | [private] |
Bind register names, to give them other names than the default.
[in] | $self | This source object |
[in] | $new | New register name |
[in] | $old | Old register name, or undef to remove mapping |
retval DASMIO::Source::regbinding | ( | scalar | self, |
scalar | reg | ||
) | [private] |
Map a register name to a standard register name.
[in] | $self | This object |
[in] | $reg | Register to lookup |
retval DASMIO::Source::write | ( | scalar | self | ) | [private] |
Write out a compilable source file based on what we have in the core.
[in] | $self | Address object |
scalar DASMIO::Source::debug_dat [private] |
scalar DASMIO::Source::debug_sym [private] |
scalar DASMIO::Source::disassemble_res_limit [private] |