Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /MLRISC/trunk/demo/eg-alpha.sml
ViewVC logotype

Annotation of /MLRISC/trunk/demo/eg-alpha.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2126 - (view) (download)

1 : leunga 713 (*---------------------------------------------------------------------------
2 :     * Here's an example: factorial for alpha.
3 :     *---------------------------------------------------------------------------*)
4 :     fun eg2() = (* fact(n) *)
5 :     let open AlphaBackEnd
6 :     val fact = C.newReg()
7 :     val i = C.newReg()
8 :     val n = C.GPReg 0 (* let's say r0 is the input/output parameter *)
9 :     val loop = Label.newLabel "loop"
10 :     val exit = Label.newLabel "exit"
11 :     in codegen
12 :     (Label.newLabel "factorial",
13 :     [T.MV(64, i, T.REG(64, n)),
14 :     T.MV(64, fact, T.LI 1),
15 :     T.DEFINE loop,
16 : leunga 744 T.BCC(T.CMP(64, T.LE, T.REG(64, n), T.LI 0), exit),
17 : leunga 713 T.MV(64, fact, T.MULS(64, T.REG(64, i), T.REG(64, fact))),
18 :     T.MV(64, i, T.SUB(64, T.REG(64, i), T.LI 1)),
19 : leunga 744 T.JMP(T.LABEL(LabelExp.LABEL loop), []),
20 : leunga 713 T.DEFINE exit,
21 :     T.MV(64, n, T.REG(64, fact)),
22 : leunga 744 T.RET []
23 : leunga 713 ]
24 :     )
25 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0