Answered step by step
Verified Expert Solution
Link Copied!

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 2 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[3], A[2]}= A[1]* A[0];
A[4]= A[2]/230;
a = A[2]%230;
b = a >>16; //'>>'= right shift
c = a & 8; //'&'= bit-wise and
d = a <<2; //'<<'= left shift
Registers Variables
$s0 A
Addresses Contents
$s0 A[0]
$s0+4 A[1]
You may use any temporary registers from $t0 to $t9 or saved registers from $s1 to $s7. Clearly specify your choice of registers and explain your code using comments (5 points).
Example Test: If the values of $s1 through $s7 are initialized in the simulator as:
Registers Data
$s04000
Addresses Contents
40004
40045
the resultant array is:
Addresses Contents
40004
40045
400820
40120
40160
402080
This is what I have:
lw $s1,0($s0) # Load A[0] into $s1
lw $s2,4($s0) # Load A[1] into $s2
mul $s3, $s1, $s2 # $s3= A[0]* A[1]
sw $s3,8($s0) # Store result in A[2]
addi $t0, $zero, 230 # Load immediate 230 into $t0
div $s3, $t0 # Divide A[2] by 230
mflo $s4 # Move quotient to $s4
mfhi $s7 # Move remainder to $s7
sw $s4,12($s0) # Store quotient in A[4]
# At this point, $s7 holds the remainder which is a
move $t2, $s7 # Move remainder to $t2
srl $s5, $t2,16 # b = a >>16
andi $s6, $t2,8 # c = a & 8
sll $s7, $t2,2 # d = a <<2
# Concatenate b, c, and d into one 32-bit value
or $t1, $s5, $s6 # $t1= b | c (middle bits)
or $t1, $t1, $s7 # $t1= b | c | d (low bits)
sll $t1, $t1,16 # Shift left to make room for b (high bits)
sw $t1,16($s0) # Store the concatenated result in A[5]
it doesnt pass these three tests:
Yours Expected
Registers $s040004000
Memory 400044
400455
40082020
401200
401652428800
402080
Yours Expected
Registers $s01380413804
Memory 13804-8-8
13808-4-4
138123232
138160-12
1382083886080
13824128
Yours Expected
Registers $s080168016
Memory 8016-5-5
802088
8024-40-40
802807
8032-655360
8036-16187552

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Discuss the five contemporary communication issues facing managers.

Answered: 1 week ago