diff --git a/cocas/assembler.py b/cocas/assembler.py index 442e9f69..7cb8bab8 100644 --- a/cocas/assembler.py +++ b/cocas/assembler.py @@ -38,7 +38,8 @@ def __init__(self, sn: TemplateSectionNode, code_segments: Type[CodeSegmentsInte elif isinstance(line, InstructionNode): if line.mnemonic not in target_instructions.assembly_directives(): - raise Exception('Only "dc" and "ds" allowed in templates') + raise Exception('Only these directives allowed in templates: ' + + ', '.join(target_instructions.assembly_directives())) for seg in target_instructions.assemble_instruction(line, temp_storage): size += seg.size diff --git a/cocas/targets/cdm16/target_instructions.py b/cocas/targets/cdm16/target_instructions.py index a2e9c1f0..8978636d 100644 --- a/cocas/targets/cdm16/target_instructions.py +++ b/cocas/targets/cdm16/target_instructions.py @@ -401,5 +401,5 @@ class Handler: ] @staticmethod - def assembly_directives() -> set[str]: - return super().assembly_directives() + def assembly_directives(): + return {'ds', 'dc', 'db', 'dw'} diff --git a/cocas/targets/cdm8/target_instructions.py b/cocas/targets/cdm8/target_instructions.py index a926d014..abab00fd 100644 --- a/cocas/targets/cdm8/target_instructions.py +++ b/cocas/targets/cdm8/target_instructions.py @@ -251,3 +251,7 @@ class Handler: 'ldi': 0xD0 }) ] + + @staticmethod + def assembly_directives(): + return {'ds', 'dc'} diff --git a/tests/resources/cdm16/input/template.asm b/tests/resources/cdm16/input/template.asm new file mode 100644 index 00000000..87384f80 --- /dev/null +++ b/tests/resources/cdm16/input/template.asm @@ -0,0 +1,44 @@ +asect 0 +main: ext # Declare labels +default_handler: ext # as external + +# Interrupt vector table (IVT) +# Place a vector to program start and +# map all internal exceptions to default_handler +dc main, 0 # Startup/Reset vector +dc default_handler, 0 # Unaligned SP +dc default_handler, 0 # Unaligned PC +dc default_handler, 0 # Invalid instruction +dc default_handler, 0 # Double fault +align 0x80 # Reserve space for the rest + # of IVT + +# Exception handlers section +rsect exc_handlers + +# This handler halts processor +default_handler> + halt + +# Templates +tplate foo +a: ds 7 +b: dc "abcd" +c: db 10 +d: dw 20 +e: ds 984 +f: dc 30 + + +# Main program section +rsect main +main> +ldi r0, foo.a +ldi r1, foo.b +ldi r2, foo.c +ldi r3, foo.d +ldi r4, foo.e +ldi r5, foo.f +ldi r6, foo._ + +end \ No newline at end of file diff --git a/tests/resources/cdm16/output/template.yaml b/tests/resources/cdm16/output/template.yaml new file mode 100644 index 00000000..e20fa68c --- /dev/null +++ b/tests/resources/cdm16/output/template.yaml @@ -0,0 +1,8 @@ +registers: + r0: 0 + r1: 7 + r2: 11 + r3: 12 + r4: 14 + r5: 998 + r6: 1000