StackTest.vm

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

StackTest.vm

Maesltrom
Hi fellows! I have some questions that are freezing me in this chapter.

1- In file Stacktest.comp, TRUE values are threaten as -1 (minus 1) and FALSE as 0 the opposite from book

2- I wrote a code to AND and OR work with -1 and 0 constants so i can't understand this part of code:

"push constant 56
push constant 31
push constant 53
add                              //31+53=84
push constant 112
sub                              //84-112=-28
neg                             //neg -28 = 28
and                             //I don't understand this AND operation here
"

Please, help me
Reply | Threaded
Open this post in threaded view
|

Re: StackTest.vm

ybakos
false is represented by 16 0 bits. true is represented as 16 1 bits, which is -1 in base 10.

The VM and operation performs a bitwise AND of the two values on the top of the stack.
Reply | Threaded
Open this post in threaded view
|

Re: StackTest.vm

cadet1620
Administrator
In reply to this post by Maesltrom
Maesltrom wrote
Hi fellows! I have some questions that are freezing me in this chapter.

1- In file Stacktest.comp, TRUE values are threaten as -1 (minus 1) and FALSE as 0 the opposite from book
The book does say that true is -1 and false is 0. There have been several other people who have also been confused by this. I think the way it is written is problematic for non-native English speakers:
    "The VM represents true and false as -1 (minus one, 0xFFFF)
   and 0 (zero, 0x0000), respectively."
It would be better, I think, to write it as:
    "The VM represents true as -1 (minus one, 0xFFFF), and
    false as 0 (zero, 0x0000)."
2- I wrote a code to AND and OR work with -1 and 0 constants so i can't understand this part of code:

"push constant 56
push constant 31
push constant 53
add                              //31+53=84
push constant 112
sub                              //84-112=-28
neg                             //neg -28 = 28
and                             //I don't understand this AND operation here
"

Please, help me
"and" is binary and of 28 with 56 which is already on the stack.
followed by "push 80; or" which does a binary or of the previous result with 80.

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

Re: StackTest.vm

Maesltrom
Awesome! Thanks Ybakos and Mark!
In morning I'll finish this chapter.

You're great guys!
Reply | Threaded
Open this post in threaded view
|

Re: StackTest.vm

Maesltrom
Good afternoon! Just one more question.
One of Chapter 7 project test is pointer.vm
isn't Pointer a later lesson? All the others tests are done

Thanks Guys
Reply | Threaded
Open this post in threaded view
|

Re: StackTest.vm

ybakos
No, it's part of chapter 7, and is addressed in that chapter of the book when describing the VM specification. Note that the pointer segment is "special."
Reply | Threaded
Open this post in threaded view
|

Re: StackTest.vm

Maesltrom
Hi ybakos!
it's the last thing that i saw in Chapter 7 talking about pointer: "pointer: discussed later." in page 25
Early there's it: "Basic idea: the mapping of the stack and the
global segments on the RAM is easy (fixed);
the mapping of the function-level segments is
dynamic, using pointers
"

I thought that a pointer is a special location where a could point to any area of stack.

Thanks. Sorry for the later answer