From 73e402bcb7cf61cc724047b0c90da4332610a9a1 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 10 Dec 2023 15:06:42 +0100 Subject: [PATCH] it works a bit --- bin/Factorial.class | Bin 0 -> 442 bytes src/Factorial.jas | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 bin/Factorial.class create mode 100644 src/Factorial.jas diff --git a/bin/Factorial.class b/bin/Factorial.class new file mode 100644 index 0000000000000000000000000000000000000000..a2af7ca00ca206f0437a8bec7c495d6fe253fef6 GIT binary patch literal 442 zcmZvX%}T>S6ot=CYRAM>W8+k-Zd{pcnuU-}#f?xX2nvO6+&I?QPDvAKQ^Ch^??x92 zE_?tV#z#Ik=X_^Azu!Lq)UfYh2YZBye|gqd_bNWW1Z^!M8I@VfGw~|ux?c+&xTqhTsIcA=?86rEkfZmyNNjsluj+Ife3ah z8xK2iLnpC=GO7e`3e#D5!Tg+E#A-kgcattjZLFZU zbSYw65xGWWNRmb`;^5L1cZS5{&zFRx-qT#51Y<7XO@V-T!TKxYj6m4nMFZQv0ccju literal 0 HcmV?d00001 diff --git a/src/Factorial.jas b/src/Factorial.jas new file mode 100644 index 0000000..5511b7d --- /dev/null +++ b/src/Factorial.jas @@ -0,0 +1,51 @@ +.class public Factorial +.super java/lang/Object + +.method public ()V + aload 0 + invokenonvirtual java/lang/Object/()V + return +.end method + +.method public static factorial(I)I ; calc `given`! + .limit locals 3 + .limit stack 5 + bipush 1 ; + istore 0 ; store the parameter `given` + bipush 1 ; we start calculating with `p`=1 + istore 1 ; store `p` + bipush 2 ; we start calculating with `j`=1 + istore 2 ; store `j` + loop: + ; p *= j + iload 1 ; load p + iload 2 ; load j + imul ; multiply p and j + istore 1 ; store p*j in p + + ; j++ + iload 2 ; load j + bipush 1 ; put a 1 on the stack + iadd ; add j and 1 + istore 2 ; store j+1 in j + + ; if j