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

For this problem, you will be asked to give an assembly answer that solves the p

ID: 3685184 • Letter: F

Question

For this problem, you will be asked to give an assembly answer that solves the problem. We are trying to accomplish a vector multiply. A vector multiply multiplies a number in one vector with the corresponding number in another vector. Some processors could do this in one single instruction, but we are going to simulate this behavior in LC-3. You may freely use all eight registers in your answer. To do this task, you will need to repeatedly multiply until all numbers in each vector have been multiplied. The input vectors will be given as follows: The length of the two vectors will be at 0x3040. The start of the first vector will be at 0x3041. The start of the second vector will be at 0x3051. The answer should be stored starting at 0x3061. Note: Neither vector will exceed 10 in length. For example, if the vectors were [3,4,5] and [1,2,3], the answer, stored at 0x3061 through 0x3063, should be [3 x 1, 4 x 2, 5 x 3] = [3,8,15]

Explanation / Answer

Answer:)

.data
strA: .asciiz "First Matrix: "
strB: .asciiz "Second Matrix: "
strC: .asciiz "Product Matrix: "
newline: .asciiz " "
space: .asciiz " "

# This is the start of the First Matrix.
matrix1: .word 111, 112, 113
.word 103, 104, 105
.word 190, 95 , 199
matrix2: .word 90, 91, 92
.word 101, 202, 303
.word 9, 10, 11

# The next statement allocates room for the product.
# The matrix takes up 4*9=36 bytes.
#.space n allocates n empty bytes in the memory
product: .space 36
.align 2

.text

# Your well-commented program starts here.
main:
li $t1, 32 # $t1 = 32 (row size/loop end)
li $s0, 0 # i = 0; initialize 1st for loop
L1: li $s1, 0 # j = 0; restart 2nd for loop
L2: li $s2, 0 # k = 0; restart 3rd for loop
sll $t2, $s0, 5 # $t2 = i * 32 (size of row of x)
addu $t2, $t2, $s1 # $t2 = i * size(row) + j
sll $t2, $t2, 3 # $t2 = byte offset of [i][j]
addu $t2, $a0, $t2 # $t2 = byte address of x[i][j]
l.d $f4, 0($t2) # $f4 = 8 bytes of x[i][j]
L3: sll $t0, $s2, 5 # $t0 = k * 32 (size of row of z)
addu $t0, $t0, $s1 # $t0 = k * size(row) + j
sll $t0, $t0, 3 # $t0 = byte offset of [k][j]
addu $t0, $a2, $t0 # $t0 = byte address of z[k][j]
l.d $f16, 0($t0) # $f16 = 8 bytes of z[k][j]
sll $t0, $s0, 5 # $t0 = i*32 (size of row of y)
addu $t0, $t0, $s2 # $t0 = i*size(row) + k
sll $t0, $t0, 3 # $t0 = byte offset of [i][k]
addu $t0, $a1, $t0 # $t0 = byte address of y[i][k]
l.d $f18, 0($t0) # $f18 = 8 bytes of y[i][k]
mul.d $f16, $f18, $f16 # $f16 = y[i][k] * z[k][j]
add.d $f4, $f4, $f16 # f4=x[i][j] + y[i][k]*z[k][j]
addiu $s2, $s2, 1 # $k k + 1
bne $s2, $t1, L3 # if (k != 32) go to L3
s.d $f4, 0($t2) # x[i][j] = $f4
addiu $s1, $s1, 1 # $j = j + 1
bne $s1, $t1, L2 # if (j != 32) go to L2
addiu $s0, $s0, 1 # $i = i + 1
bne $s0, $t1, L1 # if (i != 32) go to L1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote