From 3d75b9284b9e948c94dddbc707a94e2e7acf99f4 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sat, 13 Jul 2019 01:11:33 -0700 Subject: [PATCH] Added memcpy function to VVS stdlib. --- stdlib/README.md | 1 + stdlib/heap.pvvs | 68 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/stdlib/README.md b/stdlib/README.md index 63af366..91fa714 100644 --- a/stdlib/README.md +++ b/stdlib/README.md @@ -35,6 +35,7 @@ header comment for each function to learn the call and return stack. 10001 ----- absolute value (math.pvvs) 011xxx - heap functions 11000 ----- memset (heap.pvvs) + 11001 ----- memcpy (heap.pvvs) 100xxx - unassigned 101xxx - unassigned 110xxx - conversion functions diff --git a/stdlib/heap.pvvs b/stdlib/heap.pvvs index 62a0216..d633447 100644 --- a/stdlib/heap.pvvs +++ b/stdlib/heap.pvvs @@ -4,11 +4,11 @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Description: @ This function writes pattern into the memory locations: -@ startaddr -> startaddr+numbytes +@ startaddr -> startaddr+count @ Call Stack: @ pattern @ startaddr -@ numbytes <-- TOS +@ count <-- TOS @ Return Stack: @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -16,7 +16,7 @@ NSSVTTSSSN | Mark: 11000 (memset) @ Prepare the stack for computation. @ Addr | Contents -@ 0 | numbytes +@ 0 | count @ 1 | startaddr @ 2 | pattern @@ -41,7 +41,7 @@ SSSTSN | PUSH 2 (ptr) TTT | LOAD TTS | STORE -@ Decrement and check for loop end condition numbytes == 0. +@ Decrement and check for loop end condition count == 0. SSSSN | PUSH 0 (ptr) TTT | LOAD SNS | DUP @@ -58,4 +58,64 @@ NSSVSSSTTSSSSSSSSSSTN | Mark: 00011000 00000001 SNN | DROP NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function copies count+1 words from source to destination. +@ Call Stack: +@ source +@ destination +@ count <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTSSTN | Mark: 11001 (memcpy) + +@ Prepare the stack for computation. +@ Addr | Contents +@ 0 | count +@ 1 | destination +@ 2 | source + +SSSSN | PUSH 0 (ptr) +SNT | SWAP +TTS | STORE +SSSTN | PUSH 1 (ptr) +SNT | SWAP +TTS | STORE +SSSTSN | PUSH 2 (ptr) +SNT | SWAP +TTS | STORE + +@ Copy one word on each pass through this loop. +NSSVSSSTTSSTSSSSSSSSN | Mark: 00011001 00000000 +SSSTN | PUSH 1 (ptr) +TTT | LOAD +SSSSN | PUSH 0 (ptr) +TTT | LOAD +TSSS | ADD +SSSTSN | PUSH 2 (ptr) +TTT | LOAD +SSSSN | PUSH 0 (ptr) +TTT | LOAD +TSSS | ADD +TTT | LOAD +TTS | STORE + +@ Decrement and check for loop end conditions. +SSSSN | PUSH 0 (ptr) +TTT | LOAD +SNS | DUP +NTSSSSTTSSTSSSSSSSTN | BRZ > 00011001 00000001 +SSSTN | PUSH 1 +TSST | SUBTRACT +SSSSN | PUSH 0 (ptr) +SNT | SWAP +TTS | STORE +NSNSSSTTSSTSSSSSSSSN | JMP > 00011001 00000000 + +@ Clean up and return +NSSVSSSTTSSTSSSSSSSTN | Mark: 00011001 00000001 +SNN | DROP +NTN | RTS + #endif -- 2.20.1