Fibonacci Series in VM Emulator

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fibonacci Series in VM Emulator

gs99
When I run FibonacciSeriesVME.tst in Virtual Machine Emulator, I’m confused by two observations.

Q1. What does “pop pointer 1” do?
It appears twice – commands 1 and 20.
When command 1 runs (one-time), the value 3000 is popped to RAM[4], called THAT.
Segment That is not affected.

When command 20 runs, two results occur: RAM[4] as done in command 1.
But segment That is also affected:

Iteration:1
THAT after:3001
That[0,1,2]before:011
That[0,1,2]after:110

Iteration:2
THAT after:3002
That[0,1,2]before:112
That[0,1,2]after:120

Iteration:3
THAT after:3003
That[0,1,2]before:123
That[0,1,2]after:230

Iteration:4
THAT after:3004
That[0,1,2]before:235
That[0,1,2]after:350

These “after” values for That are pushed in commands 13 and 14 of the following iteration.
They are obviously needed.

The final values in segment That (3000, 3001 etc.): 350000

Q2.”End of script – Comparison ended successfully” appears after the final command runs.
View Output:
RAM[3000]0
RAM[3001]1
RAM[3002]1
RAM[3003]2
RAM[3004]3
RAM[3005]5
This is the correct series for 6 elements. How does this output compare with the final values in segment That?
Reply | Threaded
Open this post in threaded view
|

Re: Fibonacci Series in VM Emulator

cadet1620
Administrator
gs99 wrote
Q1. What does “pop pointer 1” do?
pop pointer only has two legal arguments: 0 and 1.
pop pointer 0 pops the top of stack into the THIS pointer which is RAM[3].
pop pointer 1 pops the top of stack into the THAT pointer which is RAM[4].
It appears twice – commands 1 and 20.
When command 1 runs (one-time), the value 3000 is popped to RAM[4], called THAT.
Segment That is not affected.
This sets the THAT pointer to 3000 so the That segment displays the content of RAM starting at 3000.
When command 20 runs, two results occur: RAM[4] as done in command 1.
But segment That is also affected:

Iteration:1
THAT after:3001
That[0,1,2]before:011
That[0,1,2]after:110
Before: THAT is 3000 so That[0..2] displays RAM[3000..3002].
After: THAT is 3001 so That[0..2] displays RAM[3001..3003].

Q2.”End of script – Comparison ended successfully” appears after the final command runs.
View Output:
RAM[3000]0
RAM[3001]1
RAM[3002]1
RAM[3003]2
RAM[3004]3
RAM[3005]5
This is the correct series for 6 elements. How does this output compare with the final values in segment That?
At the end of the test, THAT is 3004 so That[0..2] displays RAM[3004..3006].

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Fibonacci Series in VM Emulator

gs99
Thanks.
So That[0..2] is like a window of 3 units wide that moves across ram starting at 3000. Clever indeed.
Reply | Threaded
Open this post in threaded view
|

Re: Fibonacci Series in VM Emulator

gs99
However, the programmer must be aware that “pop pointer” does more than change RAM[3 or 4].

Consider “pop pointer 1”.

The VM Emulator “That” control displays the values of RAM as an object with indices starting with 0:
That
[0] 0
[1] 1
Etc. (Note: I inserted the [].)

It’s reasonable to have program variables reflecting the control (e.g. thatDict{} with [0]=0, [1]=1 etc.)
When “pop pointer 1” changes THAT, control “That” displays the changed values I reported above.
The variables need to recognize the same changes.

So the programmer must be aware of these after-effects of “pop pointer 1”.  
As you explained, it is an ever-changing view of RAM determined by the value of THAT.

In a related command “pop that 1”, I needed to add a few steps (compared to other pop commands) to recognize the changeable nature, to correctly calculate in each iteration.

I finally have a good test with FibonacciSeries!