summaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-22 17:33:07 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-22 17:33:07 +0800
commitd8ad916c80ce1e1dcfeabb8441896e94f7f00568 (patch)
treed1438afcaba312052e16e3959ba4ebeb5289351a /projects
parent51c8325661eab4667a11431175f12eb6a08cc36a (diff)
hack-vm: optimize pop by one instruction
Diffstat (limited to 'projects')
-rw-r--r--projects/hack-vm/memory.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/projects/hack-vm/memory.py b/projects/hack-vm/memory.py
index ad22482..84f4a53 100644
--- a/projects/hack-vm/memory.py
+++ b/projects/hack-vm/memory.py
@@ -44,8 +44,7 @@ D=A
@{segment}
M=M+D
@SP
-M=M-1
-A=M
+AM=M-1
D=M
@{segment}
A=M
@@ -58,8 +57,7 @@ M=M-D
# when <segment> is one of static, temp and pointer
POP_FIXED_ASM = """@SP
-M=M-1
-A=M
+AM=M-1
D=M
@{addr}
M=D