Skip to content

Commit 1c9775c

Browse files
committed
Implement "pop argument n"
1 parent 39a58f7 commit 1c9775c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/code_writer.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def write_push_pop(command, segment, index)
8080
when Parser::C_POP
8181
output.puts <<-EOF
8282
// Get base address of the local segment
83-
@LCL // A=1
83+
@#{base_address(segment)} // A=1
8484
D=M // D=RAM[1]=300
8585
// Add the index offset to the base address
8686
@#{index} // A=2
@@ -116,6 +116,13 @@ def operand(command)
116116
}.fetch(command)
117117
end
118118

119+
def base_address(segment)
120+
{
121+
'local' => 'LCL',
122+
'argument' => 'ARG'
123+
}.fetch(segment)
124+
end
125+
119126
def generate_label
120127
@counter += 1
121128
"LABEL#{@counter}"

0 commit comments

Comments
 (0)