Page 131: “All memory segments are accessed by the same two commands:
push segment index Push the value of segment[index] onto the stack.”
pop segment index Pop the top stack value and store it in segment[index].”
So then all segment memories are collections, if they have indices?
So then “push constant 7” means push constant?
The VM Emulator doesn’t show the “Constant” segment memory. How do I see what’s in this collection?
How do I see what’s in constant?
The book first says on page 131: “All the memory segments are accessed by the same two commands.”
So the reader is thinking “All the memory segments” when he reads the next two lines that talk about push and pop segment index… (segment[index]).
And concludes wrongfully that they all utilize an index in the normal way an [index] is utilized: to enable an identification of each item or value in a group (whether it’s called a collection or array). The index is not normally the value itself.
But you’re saying that the index of memory segment “constant” is not an index, but a value.
Furthermore, it has nothing to do with memory.
So the effect is simply: push 7 (as we see push 2 on page 128).
But we need to use a “memory segment” to maintain structure; call it “constant”.
Are the memory segments in Figure 7.6 recognized elsewhere, or do they only refer to Hack? If they’re standards, do you know of some books or websites that provide explanations?