Answered step by step
Verified Expert Solution
Question
1 Approved Answer
any help would be appreciated, thank you!! Given an array of 2 integers, write a program to implement the following C code that appends elements
any help would be appreciated, thank you!!
Given an array of integers, write a program to implement the following C code that appends elements to the array:
Declaration of variables
int A; Integer array A with the base address pointing to variable A
int a; char b c; short d;
Append array elements
A A A A;
A A;
a A;
b a ; right shift
c a & ; & bitwise and
d a ; left shift
Registers Variables
$s A
Addresses Contents
$s A
$s A
You may use any temporary registers from $t to $t or saved registers from $s to $s Clearly specify your choice of registers and explain your code using comments points
Example Test: If the values of $s through $s are initialized in the simulator as:
Registers Data
$s
Addresses Contents
the resultant array is:
Addresses Contents
This is what I have:
lw $s$s # Load A into $s
lw $s$s # Load A into $s
mul $s $s $s # $s A A
sw $s$s # Store result in A
addi $t $zero, # Load immediate into $t
div $s $t # Divide A by
mflo $s # Move quotient to $s
mfhi $s # Move remainder to $s
sw $s$s # Store quotient in A
# At this point, $s holds the remainder which is a
move $t $s # Move remainder to $t
srl $s $t # b a
andi $s $t # c a &
sll $s $t # d a
# Concatenate b c and d into one bit value
or $t $s $s # $t b c middle bits
or $t $t $s # $t b c d low bits
sll $t $t # Shift left to make room for b high bits
sw $t$s # Store the concatenated result in A
it doesnt pass these three tests:
Yours Expected
Registers $s
Memory
Yours Expected
Registers $s
Memory
Yours Expected
Registers $s
Memory
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