X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/blobdiff_plain/3695b659af12996f07d40088bf175a083770d573..d00258fa64b75399bf0b18368aa53222c503655c:/stdlib/heap.pvvs diff --git a/stdlib/heap.pvvs b/stdlib/heap.pvvs index 62a0216..aef5527 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,165 @@ 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 + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function writes random words into the memory locations: +@ startaddr -> startaddr+count +@ Call Stack: +@ count +@ startaddr <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTSTSN | Mark: 11010 (memrand) +SSSSN | PUSH 0 (ptr) +SNT | SWAP +TTS | STORE + +@ Store random word into one memory location on each pass through this loop. +NSSVSSSTTSTSSSSSSSSSN | Mark: 00011010 00000000 +SNS | DUP +SSSSN | PUSH 0 (ptr) +TTT | LOAD +TSSS | ADD +NSTTSSSSN | JSR > 10000 (random) +TTS | STORE + +@ Decrement and check loop end conditions +SNS | DUP +NTSSSSTTSTSSSSSSSSTN | BRZ > 00011010 00000001 +SSSTN | PUSH 1 +TSST | SUBTRACT +NSNSSSTTSTSSSSSSSSSN | JMP > 00011010 00000000 + +@ Clean up and return +NSSVSSSTTSTSSSSSSSSTN | Mark: 00011010 00000001 +SNN | DROP +NTN | RTS + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function compares two blocks of memory: +@ blk1ptr -> blk1ptr+count +@ -- versus -- +@ blk2ptr -> blk2ptr+count +@ The return value is zero if the blocks are identical, otherwise non-zero. +@ Call Stack: +@ count +@ blk1ptr +@ blk2ptr <-- TOS +@ Return Stack: +@ retvalue <-- TOS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTTSTTN | Mark: 11011 (memcmp) + +@ Prepare the stack for computation. +@ Addr | Contents +@ 0 | blk2ptr +@ 1 | blk1ptr + +SSSSN | PUSH 0 (ptr) +SNT | SWAP +TTS | STORE +SSSTN | PUSH 1 (ptr) +SNT | SWAP +TTS | STORE + +@ Compare one word on each pass through this loop. +NSSVSSSTTSTTSSSSSSSSN | Mark: 00011011 00000000 +SNS | DUP +SNS | DUP +SSSSN | PUSH 0 (ptr) +TTT | LOAD +TSSS | ADD +TTT | LOAD +SNT | SWAP +SSSTN | PUSH 1 (ptr) +TTT | LOAD +TSSS | ADD +TTT | LOAD +TSST | SUBTRACT +NTSSSSTTSTTSSSSSSTSN | BRZ > 00011011 00000010 (jump if words match) + +@ Return 'match? = false' +SNN | DROP +SSSTN | PUSH 1 +NTN | RTS + +@ Decrement and loop again if loop is not complete. +NSSVSSSTTSTTSSSSSSTSN | Mark: 00011011 00000010 +SNS | DUP +NTSSSSTTSTTSSSSSSSTN | BRZ > 00011011 00000001 (jump if loop is complete) +SSSTN | PUSH 1 +TSST | SUBTRACT +NSNSSSTTSTTSSSSSSSSN | JMP > 00011011 00000000 + +@ Return 'match? = true' +NSSVSSSTTSTTSSSSSSSTN | Mark: 00011011 00000001 +SNN | DROP +SSSSN | PUSH 0 +NTN | RTS + +#include + #endif