summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/hack-vm/branching.py4
-rw-r--r--projects/hack-vm/compare.py3
2 files changed, 4 insertions, 3 deletions
diff --git a/projects/hack-vm/branching.py b/projects/hack-vm/branching.py
index 9f94db6..684c6e1 100644
--- a/projects/hack-vm/branching.py
+++ b/projects/hack-vm/branching.py
@@ -20,7 +20,7 @@ BRANCHING_ASM = {
}
-def translate_branching(action, label, verbose=False):
+def translate_branching(action, label, prog, verbose=False):
asm = f"// {action} {label}\n" if verbose else ""
- asm += BRANCHING_ASM[action].format(label=label)
+ asm += BRANCHING_ASM[action].format(label=f"{prog}${label}")
return asm
diff --git a/projects/hack-vm/compare.py b/projects/hack-vm/compare.py
index 029236a..862281f 100644
--- a/projects/hack-vm/compare.py
+++ b/projects/hack-vm/compare.py
@@ -27,6 +27,7 @@ tag_idx = 0
def translate_compare(command, verbose=False):
global tag_idx
- asm = COMPARE_ASM.format(tag=f"{command.upper()}_{tag_idx}", jmp=JMP[command])
+ asm = f"// {command}\n" if verbose else ""
+ asm += COMPARE_ASM.format(tag=f"{command.upper()}_{tag_idx}", jmp=JMP[command])
tag_idx += 1
return asm