Question: fix the bugs. The program will get the value to calculate the factorial of , which is at x 4 0 0 0 , and
fix the bugs.
The program will get the value to calculate the factorial of which is at x and store the factorial result in xFF
Reminder to not assume the initial value of registers.
; This program calculates XX factorial It can calculate
; different numbers etc. by changing the value of the first memory
; location at the bottom of the code.
; The program does not account for zero or negative numbers as input.
; Register functions
; R always x
; R multiplication results
; R always
; R counter for outer loop
; R counter for inner loop
; R current sum
x
LD R INPUT ; Load INPUT into R using label
LD RxF ; Load into R from below
ADD RRR ; R contains input number
ADD RRR ; R contains input number
; initializes outer count
OUTERLOOP ADD RRR ; Copy outer count into inner count
; This loop multiplies via addition x
; x etc
INNERLOOP ADD RRR ; Increment sum
ADD RRR ; Decrement inner count
BRzp INNERLOOP ; Branch to inner loop if inner count
; is positive or zero
ADD RRR ; R now contains sum result from inner loop
LD RxE ; Clear Rprevious sum to
ADD RRR ; Decrement outer count
BRpz OUTERLOOP ; Branch to outer loop if outer count
; is positive or zero
ST R xxxx ; factorial result is stored in the memory location xFF
HALT
FILL x ; Can be used to initialize registers
FILL xFFFF ; s complement of ie
INPUT FILL x
RESULT FILL xFF ; At program completion, the result is stored here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
