Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer in SPIM. Please do not make the answer an image. Write a program u

ID: 670143 • Letter: P

Question

Please answer in SPIM. Please do not make the answer an image.

Write a program using MIPS assembly language to multiply two 8-bit unsigned integers x and y. For each integer as well as for the product, use a 32-bit unsigned integer representation. Since the integers are small, there should be no problem with overflow. Use repeated addition to c an y out multiplication. The algorithm is trivially simple, and does not need any explanation. The user should be able to enter a number between 0 and 255 after the prompts "Enter x" and "Enter y" are displayed on the screen. The result wall be displayed on the screen as "Product = " Do not use the mult instruction o f MIPS fo r doing any part o f this assignment Use the multiply program in Part 1 as a subroutine to compute the product of the elements of two unsigned integer arrays A and B, each of size 8. Enter the following array elements for A and B directly into the data section: A = [9,13,10, 20,1, 6 ,9 ,1 4 ] B = [41, 3, 5, 7,19, 2,1, 7] Show the result as Product = [9 times 41,13 times 3,10 times 5,..., 14 times 7] Do not use the mult instruction o f MIPS f o r doing any p art o f this assignment Only use your own program a s a subroutine/ You can declare the array elements into the data section of your program as follows. array: .byte 10,15, 7 # create a 3-element integer array initialized to 1 0 ,15, 7 ????? ? : .space 40 # reserves 40 consecutive bytes, with storage uninitialized. # You can use it as a 40-element character array, or a 10-element # integer array; a comment should explain your preference

Explanation / Answer

Answer 1: CODE -

  ## multiples.asm-- takes two numbers A and B, and prints out

## all the multiples of A from A to A * B.

## If B <= 0, then no multiples are printed.

## Registers used:

## $t0 - used to hold A.

## $t1 - used to hold B.

## $t2 - used to store S, the sentinel value A * B.

## $t3 - used to store m, the current multiple of A.

.text

main:

## read A into $t0, B into $t1.

li $v0, 5 # syscall 5 = read_int

syscall

move $t0, $v0 # A = integer just read

li $v0, 5 # syscall 5 = read_int

syscall

move $t1, $v0 # B = integer just read

blez $t1, exit # if B <= 0, exit.

mul $t2, $t0, $t1 # S = A * B.

move $t3, $t0 # m = A

loop: move $a0, $t3 # print m.

li $v0, 1 # syscall 1 = print_int

syscall # make the system call.

beq $t2, $t3, endloop # if m == S, we’re done.

add $t3, $t3, $t0 # otherwise, m = m + A.

la $a0, space # print a space.

li $v0, 4 # syscall 4 = print_string

syscall

b loop # iterate.

endloop:

la $a0, newline # print a newline:

li $v0, 4 # syscall 4 = print_string

syscall

exit:   # exit the program:

li $v0, 10 # syscall 10 = exit

syscall # we’re outta here.

## Here’s where the data for this program is stored:

.data

space: .asciiz " "

newline: .asciiz " "

## end of multiples.asm

Answer 2: CODE -