From e0d5136cb09e6ac4680796af169a611ff6c97996 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Fri, 26 Jul 2019 00:19:13 -0700 Subject: [PATCH 1/1] Added isnegative and lowbitand subroutines to VVS stdlib. --- stdlib/README.md | 4 ++-- stdlib/logic.pvvs | 23 +++++++++++++++++++++++ stdlib/math.pvvs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/stdlib/README.md b/stdlib/README.md index 099a70e..b41e251 100644 --- a/stdlib/README.md +++ b/stdlib/README.md @@ -64,8 +64,8 @@ header comment for each function to learn the call and return stack. 111000 ----- dump heap (debug.pvvs) 111001 ----- dump stack (debug.pvvs) 1xxxxxx - reserved for less common entry points - 1000000 ----- - 1000001 ----- + 1000000 ----- lowbitand (logic.pvvs) + 1000001 ----- isnegative (math.pvvs) 1000010 ----- print sign of number (stdio.pvvs) 1000011 ----- print magnitude of number (stdio.pvvs) 1000100 ----- print string from stack (stdio.pvvs) diff --git a/stdlib/logic.pvvs b/stdlib/logic.pvvs index eccc68b..b5c414d 100644 --- a/stdlib/logic.pvvs +++ b/stdlib/logic.pvvs @@ -90,4 +90,27 @@ NSSVSSTSTTSTSSSSSSSSN | Mark: 00101101 00000000 SNN | DROP NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ lowbitand (1000000) +@ Description: +@ Performs logical AND on the least-significant bit of 'X' and 'Y'. +@ Returns either 1 or 0, no other values. +@ Call Stack: +@ X +@ Y +@ Return Stack: +@ lsb(X) AND lsb(Y) +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTSSSSSSN | Mark: 1000000 (lowbitand) +SSSTSN | PUSH 2 +TSTT | MODULO +SNT | SWAP +SSSTSN | PUSH 2 +TSTT | MODULO +TSSS | ADD +SSSTSN | PUSH 2 +TSTS | DIVIDE +NTN | RTS + #endif diff --git a/stdlib/math.pvvs b/stdlib/math.pvvs index d618d83..7bd73e5 100644 --- a/stdlib/math.pvvs +++ b/stdlib/math.pvvs @@ -55,4 +55,22 @@ TSSN | MULTIPLY NSSVSSSTSSSTSSSSSSSTN | Mark: 00010001 00000001 NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ isnegative (1000001) +@ Description: +@ Returns 1 if 'number' is negative, 0 if positive. +@ Call Stack: +@ number <-- TOS +@ Return Stack: +@ 1 or 0 <-- TOS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTSSSSSTN | Mark: 1000001 (isnegative) +NTTSTSSSSSTSSSSSSSSN | BMI > 01000001 00000000 +SSSSN | PUSH 0 +NTN | RTS +NSSVSTSSSSSTSSSSSSSSN | Mark: 01000001 00000000 +SSSTN | PUSH 1 +NTN | RTS + #endif -- 2.20.1