0

Translate "let static 2 = argument 1" to VM code.

VM code (the answer):

push argument 1

pop static 2

My question

Aren't we forgetting let. Shouldn't we push another argument 1 to the stack, and then pop it to local 2 too? In order to preserve the "local type".

https://www.coursera.org/learn/nand2tetris2/lecture/z1wbL/unit-1-3-vm-abstraction-memory-segments enter image description here

Community
  • 1
  • 1
xing Zì
  • 391
  • 4
  • 16

2 Answers2

0

Not sure why you want to pop too local 2. In jack a let statement can be for field varibles too and does not have to necessarily be for local variables.

Push argument 1 would put the value in index 1 in argument segment on top of the stack which is 12.

Then you pop the top value from the stack into static 2 which is highligted in your picture

0

The keyword let in the pseudocode statement let x=y indicates to the reader that a name/value binding is about to occur, but let itself is not a variable.

You could read it as imagine x=y or assume x=y instead of let x=y if you prefer.

Alex Shroyer
  • 3,499
  • 2
  • 28
  • 54