Private Member 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 | parse_operand (scalar self, scalar lineref) |
| 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) |
| 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.
|
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:
- Character literals for values:
'X'
will evaluate to the number 88.
- Expression calculations:
1+4
will evaluate to the number 5.
Expression calculations are limited, and do not honour precedence rules. Use brackets for clarity.
- Symbols may be used in additive calculations:
data + 4
will evaluate to the value of symbol 'data
' plus 4.
Symbols may (internally) be addresses or constants:
- Address symbols are created through the standard labels.
- Address symbols may (in future versions) be subject to relocations.
- Symbols may be 'local' by preceding with a '
$
' character:
Any symbol preceded by a '$
' 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.
- Additional instructions:
DAT <value[,<value> ]*
... will write literal values to the core.
The DAT instruction is supported in the assembler, and generated in the disassembler for undefined instruction sequences.
CONST value
... will define a constant symbol with the name given in the label.
ADDRESS <value>
... will define an address symbol with the name given in the label.
- Directives:
.<directive> <parameters>
allows additional meta operations to be performed. Directives supported:
.ORIGIN address
... Sets the address for subsequent compilation
.INCLUDE file
...Includes another file at the current location
- Note:
- We should really consider changing the structure so that the DASMIO objects inherit from a parser class, rather than having to reference `$self->{'dasm'}` for parser operations like error().
Definition at line 156 of file Source.pm.