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 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...
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...
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).
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once The program should output the average, largest, and smallest of 5 numbers. You must implement the methods listed below in your program. static float getAverage(int[] data) {...} static int getLargest(int[] data) {...} static int getSmallest(int[] data) {...}
In C#, write a console-based program that asks a user to enter a number between 1...
In C#, write a console-based program that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined where you...
The program will prompt the user to enter a number between [10 .. 20] (inclusive). After...
The program will prompt the user to enter a number between [10 .. 20] (inclusive). After verifying that the number is within the proper range, you will generate that many random numbers and place them into a dynamically allocated array. Your program will then display the contents of the array (with 4 numbers per line). Next, you will sort the values in descending order (from largest to smallest). Lastly, you will display the sorted numbers (again, with 4 per line)....
Python A program which prompts the user to enter an number which is a integer n...
Python A program which prompts the user to enter an number which is a integer n and creates a tuple where the values are all numbers between 1 and n (both inclusive). Note: you can assume that the integer will always be > 1. Input Result 3 Enter an integer: 3 (1, 2, 3)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT