Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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() .macro print_int($arg) li $v0, 1 # System call code for print_int li $a0, $arg # Integer to print syscall # Print the integer .end_macro .macro print_reg_int($arg) li $v0, 1 move $a0, $arg syscall

.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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Project management skills and/or experience desirable

Answered: 1 week ago