1# Blackfin testcase for factorial 2# mach: bfin 3 4 .include "testutils.inc" 5 6 start 7 8 .macro factorial num:req answer:req 9 R0 = \num (Z); 10 CALL _fact; 11 imm32 r1, \answer; 12 CC = R1 == R0; 13 if CC JUMP 1f; 14 fail 151: 16 .endm 17 18_test: 19 factorial 1 1 20 factorial 2 2 21 factorial 3 6 22 factorial 4 24 23 factorial 5 120 24 factorial 6 720 25 factorial 7 5040 26 factorial 8 40320 27 factorial 9 362880 28 factorial 10 3628800 29 factorial 11 39916800 30 factorial 12 479001600 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 36 factorial 13 1932053504 37 pass 38 39_fact: 40 LINK 0; 41 [ -- SP ] = R7; 42 CC = R0 < 2; 43 IF CC JUMP 1f; 44 R7 = R0; 45 R0 += -1; 46 CALL _fact; 47 R0 *= R7; 481: 49 R7 = [ SP ++ ]; 50 UNLINK; 51 RTS; 52