Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Factorial iterative.asm .include ./cs47_macro.asm .data msg1: .asciiz Enter a number ? msg2: .asciiz Factorial of the number is charCR: .asciiz .text

image text in transcribed

Factorial iterative.asm

.include "./cs47_macro.asm"

.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

#

# DON'T IMPLEMENT RECURSIVE ROUTINE

# WE NEED AN ITERATIVE IMPLEMENTATION

# RIGHT AT THIS POSITION.

# DONT USE 'jal' AS IN PROCEDURAL /

# RECURSIVE IMPLEMENTATION.

print_str(msg2)

print_reg_int($s0)

print_str(charCR)

exit

cs47_macro.asm

## # 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 : 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 : exit # Usage: exit .macro exit li $v0, 10 syscall .end_macro .macro read_int($reg) li $v0,5 syscall move $reg,$v0 .end_macro .macro print_reg_int($reg) li $v0, 1 move $a0, $reg syscall .end_macro

.macro swap_hi_lo($temp1,$temp2) mfhi $temp1 mflo $temp2 move $t2, $temp1 move $t3, $temp2 mthi $t3 mtlo $t2 .end_macro .macro print_hi_lo($strHi, $strEqual, $strComma, $strLo) print_str($strHi) print_str($strEqual) li $v0,1 mfhi $a0 syscall print_str($strComma) print_str($strLo) print_str($strEqual) li $v0,1 mflo $a0 syscall .end_macro .macro lwi ($reg, $ui, $li) lui $reg, $ui ori $reg, $li .end_macro

Instructions: . Download Factorial Iterative.asm n in a directory. Copy your updated cs47_macro.asm from PA03 in the same directory. . Complete the Factorial_Iterative.asm to implement iterative factorial calculation . Assemble and execute Factorial_Iterative.asm This should create following sample output Enter a number? 10 Factorial of the number is 3628800 Upload updated Factorial_Iterative.asm (do not change the file name) Outline of high level iterative factorial. int product 1; for (int j-1; jN; j++) product *= j; Instructions: . Download Factorial Iterative.asm n in a directory. Copy your updated cs47_macro.asm from PA03 in the same directory. . Complete the Factorial_Iterative.asm to implement iterative factorial calculation . Assemble and execute Factorial_Iterative.asm This should create following sample output Enter a number? 10 Factorial of the number is 3628800 Upload updated Factorial_Iterative.asm (do not change the file name) Outline of high level iterative factorial. int product 1; for (int j-1; jN; j++) product *= j

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

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago