Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in answering these 2 questions on MIPS assembly language. Problem1.ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Create some null terminated strings to use .data strPromptFirst: .asciiz

I need help in answering these 2 questions on MIPS assembly language.

image text in transcribedimage text in transcribed

Problem1.ASM

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Create some null terminated strings to use .data strPromptFirst: .asciiz "Enter an integer value n:" strResult: .asciiz "Sum is: " strCR: .asciiz " " .text .globl main main: # STEP 1 -- get the first operand # Print a prompt asking user for input li $v0, 4 # syscall number 4 will print string whose address is in $a0 la $a0, strPromptFirst # "load address" of the string syscall # actually print the string # Now read in the first operand li $v0, 5 # syscall number 5 will read an int syscall # actually read the int move $s0, $v0 # save result in $s0 for later # STEP 2 Call the function to calculate the sum move $a0, $s0 # move the input integer n to register $a0 jal sum # jump to the function sum to calculate the sum move $s1, $v0 # move the final sum value to register $s1 # STEP 3 -- print the sum # First print the string prelude li $v0, 4 # syscall number 4 -- print string la $a0, strResult syscall # actually print the string # Then print the actual sum li $v0, 1 # syscall number 1 -- print int move $a0, $s1 # put the result in $a0 for print syscall # actually print the int # STEP 4 -- # Finally print a carriage return li $v0, 4 # syscall for print string la $a0, strCR # address of string with a carriage return syscall # actually print the string # STEP 5 -- exit li $v0, 10 # Syscall number 10 is to terminate the program syscall # exit now sum: # write your code here and final result must be stored in register $v0.

jr $ra ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CSE/EEE 230 Project 2 Due: March 12, 2021, 11:59 pm Maximum Marks: 50 Note: . To perform I/O operations in MIPS, please refer to the Problem1.asm as provided on CANVAS along with this document. A recording of the demo of running the programs is also available on CANVAS under Zoom->cloud recordings->CSE230- TA office hours. 02/26/2021 Problem 1: (10 Marks) Write a MIPS assembly program to print the sum of the first n numbers. Ask "n" as an input from the user, and print out the sum 1 + 2 + ... + (n-1) +n. Use the code in the file Probleml.asm provided with this document. Problem 2: (20 Marks) Write a recursive MIPS program to compute Greatest Common Divisor (GCD) of two positive integers X and Y. Take X and Y input from the user using I/O operation as given in Probleml.asm. An algorithm to compute GCD of X and Y is given below: if X or Y = 0 then GCD (X,Y) = 0 If X = Y then GCD (X, Y) = X else if X Y then GCD (X,Y)= GCD (X, Y-X). else GCD (X, Y) - GCD (X-Y, Y). Test your program using values of (X,Y)= (25,15). Print out the GCD (25,5) on MARS I/O window. Your answer should be 5. Problem 3: Vector Matrix Multiplication (20 Marks) Given a MxN matrix A and an N dimensional vector x. Matrix Vector product of Ax=B is shown below: For example: AL = A 11 A12 Aiz X = (*1,*+ ,*) A22 A23 ] :) A 11 A12 AX= + ArzoX + A13 X3 Aiz A23 All o X, X1 X2 A21 A22 A21. X, + A22. X2 + .3. ; for A- 1 2 1 and x = (2,2,0) 0 -3 1 2 1.2 1 - 1 + (-1). 1 t 2.0 + 1.0 2 1 AX- -3 + (-3).1 0.2 0 -3 o Perform the matrix vector multiplication by assuming the following: 1. Size of the matrix (M, N) is written in the memory at address 0x10010000 and Ox 10010004. 2. Starting the from the very next location Ox10010008, matrix A is written in row-major order in contiguous memory location. 3. After the matrix A, the vector X is written in contiguous memory locations. 4. Store the result vector B from the very next location after the Input vector X ends. You can test your program using given Matrix A and vector x below. A= 3 1 4 2 5 6 x=(1, 2, 3) Output vector B = (14, 32) Submission Instructions 1. Save your program files (one for each problem with extension.asm. 2. Comment your code well and include your name and email in each source file. 3. Zip all files into one file and upload it on CANVAS. 4. Source files: Probleml.asm, Problem2.asm, Problem3.asm 5. Zip file: LastName_FirstName_ASUID.zip 6. No Late submissions will be accepted. CSE/EEE 230 Project 2 Due: March 12, 2021, 11:59 pm Maximum Marks: 50 Note: . To perform I/O operations in MIPS, please refer to the Problem1.asm as provided on CANVAS along with this document. A recording of the demo of running the programs is also available on CANVAS under Zoom->cloud recordings->CSE230- TA office hours. 02/26/2021 Problem 1: (10 Marks) Write a MIPS assembly program to print the sum of the first n numbers. Ask "n" as an input from the user, and print out the sum 1 + 2 + ... + (n-1) +n. Use the code in the file Probleml.asm provided with this document. Problem 2: (20 Marks) Write a recursive MIPS program to compute Greatest Common Divisor (GCD) of two positive integers X and Y. Take X and Y input from the user using I/O operation as given in Probleml.asm. An algorithm to compute GCD of X and Y is given below: if X or Y = 0 then GCD (X,Y) = 0 If X = Y then GCD (X, Y) = X else if X Y then GCD (X,Y)= GCD (X, Y-X). else GCD (X, Y) - GCD (X-Y, Y). Test your program using values of (X,Y)= (25,15). Print out the GCD (25,5) on MARS I/O window. Your answer should be 5. Problem 3: Vector Matrix Multiplication (20 Marks) Given a MxN matrix A and an N dimensional vector x. Matrix Vector product of Ax=B is shown below: For example: AL = A 11 A12 Aiz X = (*1,*+ ,*) A22 A23 ] :) A 11 A12 AX= + ArzoX + A13 X3 Aiz A23 All o X, X1 X2 A21 A22 A21. X, + A22. X2 + .3. ; for A- 1 2 1 and x = (2,2,0) 0 -3 1 2 1.2 1 - 1 + (-1). 1 t 2.0 + 1.0 2 1 AX- -3 + (-3).1 0.2 0 -3 o Perform the matrix vector multiplication by assuming the following: 1. Size of the matrix (M, N) is written in the memory at address 0x10010000 and Ox 10010004. 2. Starting the from the very next location Ox10010008, matrix A is written in row-major order in contiguous memory location. 3. After the matrix A, the vector X is written in contiguous memory locations. 4. Store the result vector B from the very next location after the Input vector X ends. You can test your program using given Matrix A and vector x below. A= 3 1 4 2 5 6 x=(1, 2, 3) Output vector B = (14, 32) Submission Instructions 1. Save your program files (one for each problem with extension.asm. 2. Comment your code well and include your name and email in each source file. 3. Zip all files into one file and upload it on CANVAS. 4. Source files: Probleml.asm, Problem2.asm, Problem3.asm 5. Zip file: LastName_FirstName_ASUID.zip 6. No Late submissions will be accepted

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions