Question: ARM ASSEMBLY In this exercise you are going write a function that follows the ABI standards. This function is going to compute factorial. Recall that
ARM ASSEMBLY
In this exercise you are going write a function that follows the ABI standards. This function is going to compute factorial. Recall that 5 factorial (or 5!) is 5 * 4 * 3 * 2 * 1. Also note that 0! is 1. You must compute factorial recursively. If you use a loop rather than recursion I will take off half credit for the problem. To get you started, here is how you might write recursive factorial in C++: int fact(int n) { if (n == 0) return 1; else return n * fact(n-1); } The trick here is remembering where the result goes. Each time fact gets called, the result will be in R0. You have to save that result off in some other register, so you can then multiply it by n (which is also in R0). This one is a little tricky. Start early!
;---------------------
; Programming Assignment 5, Problem 3
; Your required header information goes here
;---------------------
; You are to write a function that computes factorial
; recursively. Given a value 'n', your function must return n!
; Some test code is given to you. After the code completes
; the following should be in the registers.
; R5 = 1 (which is 0!)
; R6 = 1 (which is 1!)
; R7 = 120 (which is 5!)
; R8 = 3628800 (which is 10!)
; R9 = 4320 (which is 7! - 6!)
tester ; DO NOT TOUCH!
MOV R0, #0
BL fact
MOV R5, R0
MOV R0, #1
BL fact
MOV R6, R0
MOV R0, #5
BL fact
MOV R7, R0
MOV R0, #10
BL fact
MOV R8, R0
MOV R0, #7
BL fact
MOV R9, R0
MOV R0, #6
BL fact
SUB R9, R9, R0
END
;---------------------
; fact function. Your code goes here!
;---------------------
fact
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
