YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -2,8 +2,6 @@ int fac_aux(int n, int acc) {
|
|||
return n < 1 ? acc : fac_aux(n - 1, acc * n);
|
||||
}
|
||||
|
||||
/*Handles negative n, Abhishek Ghosh, 1st November 2017*/
|
||||
|
||||
int fac_auxSafe(int n, int acc) {
|
||||
return n<0 ? -1 : n < 1 ? acc : fac_aux(n - 1, acc * n);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
;; Project : Factorial
|
||||
;; Date : 2018/03/09
|
||||
;; Author : Gal Zsolt [~ CalmoSoft ~]
|
||||
;; Email : <calmosoft@gmail.com>
|
||||
|
||||
(defun factorial (n)
|
||||
(cond ((= n 1) 1)
|
||||
|
|
|
|||
42
Task/Factorial/MIPS-Assembly/factorial-2.mips
Normal file
42
Task/Factorial/MIPS-Assembly/factorial-2.mips
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#reference code
|
||||
#int factorialRec(int n){
|
||||
# if(n<2){return 1;}
|
||||
# else{ return n*factorial(n-1);}
|
||||
#}
|
||||
.data
|
||||
n: .word 5
|
||||
result: .word
|
||||
.text
|
||||
main:
|
||||
la $t0, n
|
||||
lw $a0, 0($t0)
|
||||
jal factorialRec
|
||||
la $t0, result
|
||||
sw $v0, 0($t0)
|
||||
addi $v0, $0, 10
|
||||
syscall
|
||||
|
||||
factorialRec:
|
||||
addi $sp, $sp, -8 #calling convention
|
||||
sw $a0, 0($sp)
|
||||
sw $ra, 4($sp)
|
||||
|
||||
addi $t0, $0, 2 #if (n < 2) do return 1
|
||||
slt $t0, $a0, $t0 #else return n*factorialRec(n-1)
|
||||
beqz $t0, anotherCall
|
||||
|
||||
lw $ra, 4($sp) #recursive anchor
|
||||
lw $a0, 0($sp)
|
||||
addi $sp, $sp, 8
|
||||
addi $v0, $0, 1
|
||||
jr $ra
|
||||
|
||||
anotherCall:
|
||||
addi $a0, $a0, -1
|
||||
jal factorialRec
|
||||
|
||||
lw $ra, 4($sp)
|
||||
lw $a0, 0($sp)
|
||||
addi $sp, $sp, 8
|
||||
mul $v0, $a0, $v0
|
||||
jr $ra
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
REBOL [
|
||||
Title: "Factorial"
|
||||
Author: oofoe
|
||||
Date: 2009-12-10
|
||||
URL: http://rosettacode.org/wiki/Factorial_function
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue