From d60d493fa409311c2c0713c302c5f90221af6328 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 23 Aug 2022 23:41:12 +0800 Subject: hack-vm: fix branching and compare --- projects/hack-vm/branching.py | 4 ++-- projects/hack-vm/compare.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'projects') 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 -- cgit v1.2.3