diff options
Diffstat (limited to 'atk16_asm')
| -rw-r--r-- | atk16_asm/asm_ops.py | 10 | ||||
| -rw-r--r-- | atk16_asm/builtin_asm/std_bump_alloc.atk16 | 2 | ||||
| -rw-r--r-- | atk16_asm/builtin_asm/std_math.atk16 | 2 | ||||
| -rw-r--r-- | atk16_asm/builtin_asm/std_mem.atk16 | 4 | ||||
| -rw-r--r-- | atk16_asm/builtin_asm/std_term.atk16 | 3 |
5 files changed, 20 insertions, 1 deletions
diff --git a/atk16_asm/asm_ops.py b/atk16_asm/asm_ops.py index 65cf0da..1da8cf0 100644 --- a/atk16_asm/asm_ops.py +++ b/atk16_asm/asm_ops.py @@ -346,6 +346,16 @@ def expand_calli(addr_imm: int | str) -> ExpandResult: ] @register_macro +def expand_call(label: str, clobber_r = "RF") -> ExpandResult: + """Convenience wrapper for ldi + ldr + callr, clobbers RF by default.""" + pointer_label = f"{label}_p" + return [ + ["ldi", pointer_label, clobber_r], + ["ldr", clobber_r, clobber_r], + *expand_callr(clobber_r), + ] + +@register_macro def expand_return() -> ExpandResult: return [ ["str", "RG", "SP"], # store returned value on stack but don't increment SP diff --git a/atk16_asm/builtin_asm/std_bump_alloc.atk16 b/atk16_asm/builtin_asm/std_bump_alloc.atk16 index 32516bc..28eefbc 100644 --- a/atk16_asm/builtin_asm/std_bump_alloc.atk16 +++ b/atk16_asm/builtin_asm/std_bump_alloc.atk16 @@ -24,6 +24,7 @@ @data bump_next_p heap_segment @data bump_arena_start ${heap_segment - 1} +@data bump_reset_p bump_reset @label bump_reset ; reset the heap to its initial state (zero allocated blocks) ; can be used to initialize the bump allocator @@ -42,6 +43,7 @@ stack_restore RA RB return +@data bump_alloc_p bump_alloc @label bump_alloc ; allocate a block of memory from the heap, checking for overlap with the stack ; parameters: RA = n of words to allocate diff --git a/atk16_asm/builtin_asm/std_math.atk16 b/atk16_asm/builtin_asm/std_math.atk16 index 6544b32..10b90c3 100644 --- a/atk16_asm/builtin_asm/std_math.atk16 +++ b/atk16_asm/builtin_asm/std_math.atk16 @@ -1,6 +1,7 @@ @data mul_sign_mask ${2 ** 15} @data mul_not_mask 0xFFFF +@data mul_p mul @label mul ; multiply a signed (a) and a signed (b) ; parameters RA = a @@ -71,6 +72,7 @@ ; Calling convention is that arguments are in registers RA..RG (max 7 arguments since RH = SP) ; and the return value is in RG (note: overwriting arg in RG) +@data fact_p fact @label fact ; parameters RA = n ; return RG = factorial(n) diff --git a/atk16_asm/builtin_asm/std_mem.atk16 b/atk16_asm/builtin_asm/std_mem.atk16 index 5855879..26aac45 100644 --- a/atk16_asm/builtin_asm/std_mem.atk16 +++ b/atk16_asm/builtin_asm/std_mem.atk16 @@ -1,3 +1,4 @@ +@data memset_p memset @label memset ; sets a specified number of words in memory to a specified value ; parameters: RA = offset (offset in memory to start at) @@ -19,6 +20,7 @@ stack_restore RD RE return +@data memcopy_p memcopy @label memcopy ; copies a specified number of words from one location in memory to another ; parameters: RA = src (source address) @@ -42,6 +44,7 @@ stack_restore RD RE RF return +@data memcompare_p memcompare @label memcompare ; compares two blocks of memory ; parameters: RA = src1 (source address 1) @@ -77,6 +80,7 @@ return +@data string_compare_p string_compare @label string_compare ; compares two strings ; parameters: RA = str1 (source address 1) diff --git a/atk16_asm/builtin_asm/std_term.atk16 b/atk16_asm/builtin_asm/std_term.atk16 index b0c9f4f..9a7af5f 100644 --- a/atk16_asm/builtin_asm/std_term.atk16 +++ b/atk16_asm/builtin_asm/std_term.atk16 @@ -1,3 +1,4 @@ +@data log_term_char_p log_term_char @label log_term_char ; send a character to the terminal ; parameters: RA = character code @@ -11,7 +12,7 @@ return - +@data log_term_string_p log_term_string @label log_term_string ; send a string to the terminal ; parameters: RA = address of string allocation |
