Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For our 3 times 3 case, the circuit computes: Y 1 1 = W 1 1 times X 1 1 + W 1
For our times case, the circuit computes:
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Y Wtimes X Wtimes X Wtimes X
Write MIPS code to implement the above times multiplier. All of the W and X
values need to be loaded from memory, and all of the resulting Y values are stored into memory. You can use registers for holding partial products and of course the registers are used when loading values to and from memory This is doing floating point adds and multiplies, so try to design your code to minimize stalls. How many cycles does it take to perform this operation?
I have already written the mips code for this question. Can you please evaluate to see if it is okay? Also can you answer me the question of "How many cycles does it take to perform this operation?"
data
dimensions: word # Square matrix length row width, column height kept same for simplicity.
matrixsize: word # Total size x
weights: float # Fill weights with arbitrary values. from left to right W W W W W W W W W
X: float # Fill memory X with arbitrary values. from left to right X X X X X X X X X
Y: float # Initialize result array with values Y Y Y Y Y Y Y Y Y
offset: word # Single precision floating offset value
newline: asciiz
# New line constant
zero: word # Zero value constant
siva: asciiz "Program designed and executed by Siva Charan Mallena, Bronco Id:
text
globl main
main:
la $s X #load address of X variable
la $s weights #load address of weights variable
lw $s dimensions #dimension size into register
la $s Y #load address of resulting matrix
lw $s offset #load offset into a register
lw $s matrixsize #total matrix size into register
li $s #print loop counter
li $t #row loop counter
li $t #col loop counter
li $t #multaddloop counter
lwc $f zero #load zero into temp register for zeroing Y value later
j rowloop #start! jump to matrix multiplication loop
li $v #exit out! this is not necessary i guess, since there is an exit method which will be called by rowloop
syscall
rowloop: # i
bge $t $s resetYaddressandprint # break out to printing final result Y
j colloop # jump to inner loop
colloopret: # return location for colloop
addi $t $t # increment row loop counter
li $t # reset col loop counter
j rowloop # looop
colloop: # j
bge $t $s colloopret # break out to rowloop upon completion
lwc $f$s # load current Y location value into $f
j multaddloop # jump to multiplication and add loop
multaddloopret: # return locatioin for multaddloop
ss $f$s # Save $f back to its current pointed address
add $s $s $s # increment Ys location for the next Y value
addi $t $t # increment colloop counter
li $t # reset multaddloop counter
mov.s $f $f # reset $f value to
j colloop # loooop
multaddloop: # k
bge $t $s multaddloopret # break out to colloop
# W offset j k
mul $t $t $s # j
add $t $t $t # j K;
mul $t $t $s # multiply offset with length of wordsingle precision. t is absolute offset. which means address of w must be pointed to first element then $t must be added.
add $t $s $t # get address of value to be fetched for W
lwc $f$t # load actual value to FP register
#X offset i k
mul $t $t $s # i
add $t $t $t # i k; t is absolute offset. which means address of w must be pointed to first element then $t must be added.
mul $t $t $s # multiply offset with length of wordsingle precision
add $t $s $t # get address of value to be fetched for W
lwc $f$t # load actual value to FP register
mul.s $f $f $f # both W and X values are loaded. now multiply
add.s $f $f $f # Y YWX
addi $t $t # increment multaddloop counter
j multaddloop # loooop
resetYaddressandprint:
la $s Y
la $a siva # load my name
li $v # load print text command to $v
syscall
j printY
printY:
bge $s $s endprogram # break out to exit
li $v # print from $f
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started