OLD | NEW |
1 # Blackfin testcase for factorial | 1 # Blackfin testcase for factorial |
2 # mach: bfin | 2 # mach: bfin |
3 | 3 |
4 .include "testutils.inc" | 4 .include "testutils.inc" |
5 | 5 |
6 start | 6 start |
7 | 7 |
8 .macro factorial num:req answer:req | 8 .macro factorial num:req answer:req |
9 R0 = \num (Z); | 9 R0 = \num (Z); |
10 CALL _fact; | 10 CALL _fact; |
(...skipping 10 matching lines...) Expand all Loading... |
21 factorial 3 6 | 21 factorial 3 6 |
22 factorial 4 24 | 22 factorial 4 24 |
23 factorial 5 120 | 23 factorial 5 120 |
24 factorial 6 720 | 24 factorial 6 720 |
25 factorial 7 5040 | 25 factorial 7 5040 |
26 factorial 8 40320 | 26 factorial 8 40320 |
27 factorial 9 362880 | 27 factorial 9 362880 |
28 factorial 10 3628800 | 28 factorial 10 3628800 |
29 factorial 11 39916800 | 29 factorial 11 39916800 |
30 factorial 12 479001600 | 30 factorial 12 479001600 |
31 » factorial 13 6227020800 | 31 # This is the real answer, but it overflows 32bits. Since gas itself |
| 32 # likes to choke on 64bit values when compiled for 32bit systems, just |
| 33 # specify the truncated 32bit value since that's what the Blackfin will |
| 34 # come up with too. |
| 35 #» factorial 13 6227020800 |
32 factorial 13 1932053504 | 36 factorial 13 1932053504 |
33 pass | 37 pass |
34 | 38 |
35 _fact: | 39 _fact: |
36 LINK 0; | 40 LINK 0; |
37 [ -- SP ] = R7; | 41 [ -- SP ] = R7; |
38 CC = R0 < 2; | 42 CC = R0 < 2; |
39 IF CC JUMP 1f; | 43 IF CC JUMP 1f; |
40 R7 = R0; | 44 R7 = R0; |
41 R0 += -1; | 45 R0 += -1; |
42 CALL _fact; | 46 CALL _fact; |
43 R0 *= R7; | 47 R0 *= R7; |
44 1: | 48 1: |
45 R7 = [ SP ++ ]; | 49 R7 = [ SP ++ ]; |
46 UNLINK; | 50 UNLINK; |
47 RTS; | 51 RTS; |
OLD | NEW |