nand2tetris/compiler/backend/lib/programflow.ml

13 lines
253 B
OCaml
Raw Permalink Normal View History

open! Ast
open! Base
let addr a = "@" ^ a
let label name = "(" ^ name ^ ")"
let translate command name =
match command with
| Label -> [ label name ]
| Goto -> [ addr name; "0;JMP" ]
| Ifgoto -> [ "@SP"; "AM=M-1"; "D=M"; addr name; "D;JNE" ]