diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-04-13 22:46:53 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-04-13 22:46:53 +0300 |
| commit | 915846b9898f74308509346ba94db0dd2ba1de45 (patch) | |
| tree | f450a174bb33bef47114f2f07433464e4af27459 /atk16_asm/builtin_asm | |
| parent | a36e5e001a4f17505c40b7f7a8f9c1f514f40de1 (diff) | |
Add memcopy, add test
Diffstat (limited to 'atk16_asm/builtin_asm')
| -rw-r--r-- | atk16_asm/builtin_asm/std_mem.atk16 | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/atk16_asm/builtin_asm/std_mem.atk16 b/atk16_asm/builtin_asm/std_mem.atk16 index 7a7efab..43d00ea 100644 --- a/atk16_asm/builtin_asm/std_mem.atk16 +++ b/atk16_asm/builtin_asm/std_mem.atk16 @@ -18,3 +18,26 @@ @label memset_done stack_restore RD RE return + +@label memcopy + ; copies a specified number of words from one location in memory to another + ; parameters: RA = src (source address) + ; RB = dest (destination address) + ; RC = n (number of words to copy) + ; returns: void + stack_stash RD RE RF + ldi 0 RD ; RD := i (counter), initially 0 +@label memcopy_loop + sub RC RD RE ; RE := n – i (unused value) + bri zero memcopy_done ; exit the loop + + add RA RD RE ; RE := src + i (address of the word to copy) + ldr RE RE ; RE := the word at address RE + add RB RD RF ; RF := dest + i (address of the word to copy to) + str RE RF ; set the word at address RF to the word in RE + + inc RD ; i := i + 1 + jpi memcopy_loop ; repeat the loop +@label memcopy_done + stack_restore RD RE RF + return |
