chapter 7 page 138 pop pointer 1?

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

chapter 7 page 138 pop pointer 1?

nand2cy
chapter 7 page 138 pop pointer 1?

Why it is not pop pointer 0?

push local 0
push constant 2
add
pop pointer 1
push constant 19
pop that 0
Reply | Threaded
Open this post in threaded view
|

Re: chapter 7 page 138 pop pointer 1?

cadet1620
Administrator
nand2cy wrote
Why it is not pop pointer 0?

push local 0
push constant 2
add
pop pointer 1
push constant 19
pop that 0
"pop pointer 0" sets the base of the this segment.
"pop pointer 1" sets the base of the that segment.

This example could have used pointer 0 and this, but the convention used by the Jack compiler is that the that segment is used for accessing array elements.

Figure 7.11 shows the convention for accessing object fields (member variables) using pointer 0 and this.

--Mark