Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. AREA |.text|, CODE, READONLY
  2.  
  3. ; int factorial(int N);
  4.  
  5. EXPORT factorial
  6.  
  7. factorial ; On entry, N is stored in R0.
  8. MOVS r1, r0 ; R1 is our loop counter. Copy N to R1 and test.
  9. MOVEQ r0, #1 ; if (R1 == 0) Set result to 1 and fall through to return...
  10. loop
  11. SUBNES r1, r1, #1 ; if (R1 != 0) Decrement R1 and test.
  12. MULNE r0, r1, r0 ; if (R1 != 0) Result = R1 * Result.
  13. BNE loop ; if (R1 != 0) Loop.
  14. MOV pc, r14 ; Return with result in R0.
  15.  
  16. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement