Question

In: Computer Science

Prompt user to enter an integer number from console. Use 2 methods to multiply this number...

Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result.

This is required to be done in MIPS Assembly Language.

Solutions

Expert Solution

Method 1: Multiplication is defined as add the multiplier(m) to the itself the number of time in the multiplicand(n) time. Thus a definition is the following: M(m,n) = m(when n = 1), else will be M(m, n-1) Here we are taking n=7 as we have to multiply it with 7

This is done in pseudo code here.

subprogram global main()

{

register int multiplicand

register int multiplier

register int answer

m = prompt("Enter the multiplicand")

n = prompt("Enter the multiplier")

answer = Multiply(m, n)

print("The answer is: " + answer)

}

subprogram int multiply(int m, int n)

{

if (n == 1)

return m;

return m + multiply(m,n-1)

}

Method 2: Put n=7 for multiplying by 7

.text

.globl main

main:

# register conventions

# $s0 - m

# $s1 - n

# $s2 - answer

la $a0, prompt1 # Get the multiplicand

jal PromptInt

move $s0, $v0 la $a0, prompt2 # Get the multiplier

jal PromptInt

move $s1, $v0

move $a0, $s0

move $a1, $s1

jal Multiply # Do multiplication

move $s2, $v0

la $a0, result #Print the answer

move $a1, $s2

jal PrintInt

jal Exit

Multiply:

addi $sp, $sp -8 # push the stack

sw $a0, 4($sp) #save $a0

sw $ra, 0($sp) # Save the $ra

seq $t0, $a1, $zero # if (n == 0) return

addi, $v0, $zero, 0 # set return value

bnez $t0, Return

addi $a1, $a1, -1 # set n = n-1

jal Multiply # recurse

lw $a0, 4($sp) # retrieve m

add $v0, $a0, $v0 # return m+multiply(m, n-1)

Return:

lw $ra, 0($sp) #pop the stack

addi $sp, $sp, 8

jr $ra

.data

prompt1: .asciiz "Enter the multiplicand: "

prompt2: .asciiz "Enter the multiplier: "

result: .ascii "The answer is: "

.include "utils.asm"


Related Solutions

Prompt user to enter an integer number from console. Use 2 methods to multiply this number...
Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result. This is required to be done in MIPS Assembly Language.
Prompt user to enter an integer number from console. Use 3 methods to check if this...
Prompt user to enter an integer number from console. Use 3 methods to check if this number is even or odd. Display result. This is required to be done in MIPS assembly language.
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from...
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from small to great. This is required to be done in MIPS assembly language.
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
4. Prompt user to enter a double number from console. Round this number so it will...
4. Prompt user to enter a double number from console. Round this number so it will keep 2 places after the decimal point. Display new number. For example, number 12.3579 will round to 12.36; number 12.4321 will round to 12.43 This is meant to be written in Java 14.0
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT