nand2tetris/compiler/backend/lib/return.ml
Konarak b7dee58454
finish project eight backend compiler
- modify existing implementation to use variant types for a more
  accurate representation of the vm byte code
- switch to fold from recursion for the main translate function
- use separate modules for translating different vm commands
- move static arithmetic command translations to a map
2024-09-13 17:03:52 -04:00

48 lines
635 B
OCaml

let translate =
[ "// Save LCL to R14, Return Address to R15 "
; "@LCL"
; "D=M"
; "@R14"
; "M=D"
; "@R5"
; "A=D-A"
; "D=M"
; "@R15"
; "M=D"
; "// POP return value to ARG0, SP=ARG+1 "
; "@SP"
; "AM=M-1"
; "D=M"
; "@ARG"
; "A=M"
; "M=D"
; "D=A"
; "@SP"
; "M=D+1"
; "// reposition THAT, THIS, ARG, LCL "
; "@R14"
; "AM=M-1"
; "D=M"
; "@THAT"
; "M=D"
; "@R14"
; "AM=M-1"
; "D=M"
; "@THIS"
; "M=D"
; "@R14"
; "AM=M-1"
; "D=M"
; "@ARG"
; "M=D"
; "@R14"
; "AM=M-1"
; "D=M"
; "@LCL"
; "M=D"
; "// Jump to Return Address "
; "@R15"
; "A=M"
; "0;JMP"
]