I am required to write a factorial function in ARM assembly language that takes an integer $ n $ as input and returns the value of $ n! $. However, I can only use the $ 4 $ basic arithmetic operations $ + - * / $ (so no if-else or loop or recursion). Can anyone suggest a hint to do that? I can only do if I am allowed to use if-else or recursion.
we were required to do something similar. We were given a number to calculate, which was 7!.r0 will hold the final value. I ended up doing the following:
MOV r1, #7 MOV r1, #6 MOV r1, #5 MOV r1, #4 MOV r1, #3 MOV r1, #2 MOV r1, #1
MUL r0, r1, r2 MUL r0, r0, r3 MUL r0, r0, r4 MUL r0, r0, r5 MUL r0, r0, r6 MUL r0, r0, r7