Question: This mips code: # initialize B [ 0 ] to 1 ( A [ 0 ] ^ 0 = 1 ) addi $t 0 ,
This mips code:
# initialize B to A
addi $t $t
sw $t$s
# initialize n to since B is already set
ori $s $zero,
# initialize loop var j to
ori $t $zero,
start:
# exit loop if j n
bge $t $s loopend
# calculate Aj address and load Aj
sll $t $t # offset j
add $t $s $t # find address of Aj
lw $t$t # load Aj into t
# find exponentAj
j
move $a $t # aj argument
move $a $t # j arg
jal exp # call to exponent callee
move $t $v # store result v in t
#move result into B
move $a $s # pass base adress of B
move $a $s # pass length of B n
move $a $t # store result into t
jal append # call to append func
addi $s $s #n
#increment loop counter j
addi $t $t
j start
# exponent func int expintx inty
exp:
move $t $a # move x to t
move $t $a # y to t
ori $t $zero, # exp
beq $t $zero, expend #if y return
exploop:
mul $t $t $t # exp x
addi $t $t # y
slt $t $zero, $t # t if t
bne $t $zero, exploop # t repeat until y
expend:
move $v $t # return val in v
jr $ra
append:
sll $t $a # find offset n
add $t $a $t # calc adress of Bn
sw $a$t #store exp at Bn
jr $ra
loopend:
Is supposed to mimic the following C pseudocode:
# Change your C code here if different
#int main
# B; th element A
# for int j ; j n; j
# n j; Current length of array B
# exp exponentAj j;
# appendB n exp;
#
# n;
#
#int exponentint x int y
# int exp x;
# for int j ; j y; j
# exp exp x;
#
# returnexp;
#
#void appendint B int n int exp
# Bn exp;
#
Where register s is A s is n s is B and s is n
I cannot find a reason as to why it hasn't been outputting the expected values i've tested it with,
If someone NOT CHATGPT PLS could help me with this it'd be greatly appreciated.
Registers Variables
$s A
$s n
$s B
$s n
Addresses Contents
$s A
$s A
$sn An
Gets tested with:
Registers Data
$s
$s
$s
$s
Addresses Contents
Expect to get:
The resultant registers will be:
Registers Data
$s
$s
The resultant array B is:
Addresses Contents
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
