From f09280141f18fbe8cef0ed576cf932e12e315666 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 17 Sep 2018 22:57:10 -0700 Subject: 4548: start of a compiler for a new experimental low-level language --- subx/apps/factorial.k2 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 subx/apps/factorial.k2 (limited to 'subx/apps/factorial.k2') diff --git a/subx/apps/factorial.k2 b/subx/apps/factorial.k2 new file mode 100644 index 00000000..82c44352 --- /dev/null +++ b/subx/apps/factorial.k2 @@ -0,0 +1,21 @@ +fn factorial n : int -> result/EAX : int [ + result/EAX <- copy 1 + { + compare n, 1 + break-if <= + var tmp/EBX : int + tmp/EBX <- copy n + tmp/EBX <- subtract 1 + var tmp2/EAX : int + tmp2/EAX <- call factorial, tmp/EBX + result/EAX <- multiply tmp2/EAX, n + } + return result/EAX +] + +data structures: + +add entry for "factorial" into the Types table, with value (fn int -> int) +add entry for "factorial" into the address table, with value next available address +add entry for "factorial" into the size table, with value size of "0b 0a bb ..." +increase next available address by size of "factorial" -- cgit 1.4.1-2-gfad0