Question
Write an assembly program to compute factorial. Assemble and execute Factorial_Iterative.asm This should create following sample output Enter a number ? 10 Factorial of the
Write an assembly program to compute factorial.
Assemble and execute Factorial_Iterative.asm This should create following sample output
Enter a number ? 10 Factorial of the number is 3628800
--------------------
#<------------------ MACRO DEFINITIONS ----------------------># # Macro : print_str # Usage: print_str(
) .macro print_str($arg) li $v0, 4 # System call code for print_str la $a0, $arg # Address of the string to print syscall # Print the string .end_macro .macro read_int($arg) # read int li $v0, 5 syscall move $arg, $v0 .end_macro # Macro : print_int # Usage: print_int(.end_macro .macro swap_hi_lo($temp1, $temp2) mfhi $temp1 mflo $temp2 move $t0, $temp1 move $t1, $temp2 mthi $t1 mtlo $t0 syscall .end_macro .macro print_hi_lo($strHi, $strEqual, $strComma, $strLo, $strEqual) li $v0, 4 la $a0, $strHi syscall li $v0, 4 la $a0, $strEqual syscall li $v0, 1 mfhi $a0 #Print the hi after swapping syscall li $v0, 4 la $a0, $strComma syscall li $v0, 4 la $a0, $strLo syscall li $v0, 4 la $a0, $strEqual syscall li $v0, 1 mflo $a0 #Print the lo after swapping syscall .end_macro # Macro : exit # Usage: exit .macro exit li $v0, 10 syscall .end_macro
-----------------------
.data msg1: .asciiz "Enter a number ? " msg2: .asciiz "Factorial of the number is " charCR: .asciiz " "
.text .globl main main: print_str(msg1) read_int($t0) # Write body of the iterative # factorial program here # Store the factorial result into # register $s0 print_str(msg2) print_reg_int($s0) print_str(charCR) exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started