Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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