48 lines
635 B
OCaml
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"
|
||
|
]
|