Help with explanation of Statics Test

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

Help with explanation of Statics Test

Nishant
This post was updated on .
Hello, I had a question regarding the working of statics test
In statics test I initially call function class1.set with input arguments 6 and 8
function Class1.set 0
push argument 0.                
pop static 0                       ---Here I set static 0 to 6
push argument 1
pop static 1                       ---Here I set static 1 to 8
push constant 0
return
Then I call function class2.set with input arguments 23 and 15
function Class2.set 0
push argument 0
pop static 0                       ---Here static 0 is rewritten to 23
push argument 1
pop static 1                       ---Here static 1 is rewritten to 15
push constant 0
return
Now when I call Class1.get
function Class1.get 0
push static 0
push static 1
sub                                   ---here23-15=8
return
So ram 261 is set to 8 then why does the VM emulator compute (6-8) instead and give -2?
Isn't the static memory segment a global Memory segment that can be rewritten by the function?
I get output | RAM[0]=263 |RAM[261]=8.  |RAM[262]|=8
where am I going wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

WBahn
Administrator
I'm assuming that your Class1 and Class2 refer to two different .vm files.

If so, then the key to remember is that EACH .vm file has its own, separate, static memory segment. A static memory segment is visible to all functions within a .vm file -- and ONLY to the functions within that .vm file.

So when you call Class1.set, you store 6 and 8 into Class1's static memory segment and when you call Class2.set you store 23 and 15 into Class2's static memory segment. Then when you call Class1.get you retrieve values from Class1's memory segment, which mean that you get the 6 and 8 back.
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

Stormtrooper2001
In reply to this post by Nishant
Every function has its own set of static variables. Class2.set can't overwrite the static segment of Class1. This isn't covered in much detail in the course.
The way they expect us to do it is s follows:
Push static 0 in the Class1 function will push the value into a variable named class1.0 and the same line in Class2 will push the value into a variable named class2.0
If you are doing the course on Coursera this is covered in video 1.5 starting about 13:00
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

Stormtrooper2001
In reply to this post by WBahn
This might be a better explanation
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

WBahn
Administrator
In reply to this post by Stormtrooper2001
Stormtrooper2001 wrote
Every function has its own set of static variables. Class2.set can't overwrite the static segment of Class1. This isn't covered in much detail in the course.
The way they expect us to do it is s follows:
Push static 0 in the Class1 function will push the value into a variable named class1.0 and the same line in Class2 will push the value into a variable named class2.0
If you are doing the course on Coursera this is covered in video 1.5 starting about 13:00
This is likely a typo, but it isn't that every function has its own set of static variables, but that every .vm file has its own set.
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

Stormtrooper2001
Yes that's what I meant my bad.
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

Nishant
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Help with explanation of Statics Test

Nishant
In reply to this post by Stormtrooper2001
Thank you