diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-08-23 23:41:12 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-08-23 23:41:12 +0800 |
commit | d60d493fa409311c2c0713c302c5f90221af6328 (patch) | |
tree | dee225d83969acac23af4bfa41e8d1d1c52581ea /projects | |
parent | 1568a0caccc2c264a322dadf81bab16b68195f87 (diff) |
hack-vm: fix branching and compare
Diffstat (limited to 'projects')
-rw-r--r-- | projects/hack-vm/branching.py | 4 | ||||
-rw-r--r-- | projects/hack-vm/compare.py | 3 |
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 |