• Welcome to Jose's Read Only Forum 2023.
 

I32 Numbers Stack Include File for your Library

Started by Theo Gottwald, January 10, 2011, 08:57:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

What is a numbers stack?

Its just like a "Stack of Paper". You can put one thing at the Top and when you need it, you can remove it. Thats called "Push and Pop".

You PUSH something on the STACK, and you POP it off the Stack later.

There are places in Information scienece where you need a numbers stack.
If you parse Source code for example.

The CPU has their own Numbers Stack and PUSH and POP commands.
You may need one in your program for you own uses.
Here is one.

You can do the following usingthis I32_Stacklinb.inc:

SUB I32_Push1(BYVAL dwVal AS DWORD)    ' Push ONE Number onto the Stack
SUB I32_Push2(BYVAL dwA AS DWORD,BYVAL dwB AS DWORD)  ' Push Two Numbers onto the Stack
FUNCTION I32_Pop() AS DWORD   ' POP one Number off the Stack
SUB I32_Swap() ' Swap the most upper Stack positions
SUB I32_Xap() ' Swap two Stack-Elements identified by their Index Position
SUB I32_Join(BYREF T01 AS STRING)   ' Put the whole Stack into a String
SUB I32_Unjoin(BYREF T01 AS STRING)  ' Get the whole Stack (back) out of a String
SUB I32_Clear()  ' Clear the Stack - start a new one.
SUB I32_Dump() ' Take a look on your Stack

Lets talk about Speed:
I get 1 Seconds for Pushing and Popping 800.000 Items.
Then to Join and Unjoin this resulting Stack with 400.000 Items for 10 times, i get here: 1 Second.

This way you can have unlimited Number of Stacks. Just Join one into a String,
keep it for later.
Then clear the Stack, use it in your Subprogram.
Clear it again, and Restore your Previous stack using Unjoin.