Inspired by Sandor Schneider's "STABLE" project I decided that it was time to update the code that handles the stack manipulations, particularly important for arithmetic, logical and comparison operations.
I found that a 4 level stack based on registers was not only limited but difficult to manage without a lot of time wasted shuffling registers.
Using Sandor's approach, there is an array in memory st[ ] which is accessed by a stack pointer variable s. The top item on the stack is st[s] and the next item on the stack is st[s-1].
The only operations needed now to handle the stack are pre-increment or post-decrement the stack pointer using s++ or s--.
Here are the arithmetical instructions recoded to use this technique:
//---------------------------------------------------------------------
// Arithmetical, Logical and Comparison operations:
case '+': st[s-1]+=st[s]; s-- ; break; // ADD
case '-': st[s-1]-=st[s]; s-- ; break; // SUB
case '*': st[s-1]*=st[s]; s-- ; break; // MUL
case '/': st[s-1]/=st[s]; s-- ; break; // DIV
case '_': st[s]=-st[s]; break; // NEG
case '&': st[s-1]&=st[s]; s-- ; break; // AND
case '|': st[s-1]|=st[s]; s-- ; break; // OR
case '^': st[s-1]^=st[s]; s-- ; break; // XOR
case '~': st[s]= ~st[s]; break; // NOT
case '<': if(st[s]> st[s-1]){st[s]=-1;}else{st[s]=0;} break; // LT
case '>': if(st[s]< st[s-1]){st[s]=-1;}else{st[s]=0;} break; // GT
case '=': if(st[s]==st[s-1]){st[s]=-1;}else{st[s]=0;} break; // EQ
SIMPL continues to be a world of exploration.
When running on the 600MHz Teensy 4.0 it has lightning speed.
50 million empty loops per second
9.2 million 32-bit addition or subtractions per second
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.