summaryrefslogtreecommitdiff
path: root/mipshelpers.ml
blob: b93ae6c250b7492162cad3665aae09c3c12d128b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(****************************************
    mipshelpers.ml - "macros" mips
 ****************************************)

open Mips

let heap_push n =
    [Comment (Printf.sprintf "heap_push %d" n) ;
     Addi (SP, SP, - n)]
let heap_pop n =
    [Comment (Printf.sprintf "heap_pop %d" n) ;
     Addi (SP, SP, n)]

let push reg =
    [Addi (SP, SP, -4) ;
     Sw (reg, (0, SP))]

let pop reg =
    [Lw (reg, (0, SP)) ;
     Addi (SP, SP, 4)]

let malloc n =
    [Comment (Printf.sprintf "Malloc %d" n) ;
     Li (V0, 9) ;
     Li (A0, n) ;
     Syscall]