Write the code in MIPs called split. Routine split is called with four arguments
ID: 3787850 • Letter: W
Question
Write the code in MIPs called split. Routine split is called with four arguments. Register a0 holds the number of elements in an input array, register a1 holds the address of the input array. The input array consists of 4-byte elements. Register a2 holds the address of a 4-byte-element output array and register a3 holds the address of a 2-byte-element output array. Complete split so that it copies elements from the input array to the 2-byte output array (if it fits), otherwise to the 4-byte output array. The return value, in register v0, should be the number of elements in the 4-byte output array when copying is done.
# CALL VALUES:
# $a0: Number of elements in input array.
# $a1: Address of input array. Elements are 4 bytes each.
# $a2: Address of output array, elements are 4 byte each.
# $a3: Address of output array, elements are 2 byte each.
#
# RETURN:
# $v0, Number of elements in 4-byte output array.
# Write small elements in $a3 array and large elements in $a2.
#
# Note:
# Can modify $t0-$t9, $a0-$a
Explanation / Answer
// none of these allocate any storage #define MAX_SIZE 256 #define IF(a) if (a) { #define ENDIF } typedef struct { unsigned char red; // 'unsigned char' is an unsigned, 8-bit int unsigned char green; unsigned char blue; unsigned char alpha; } RGBa; // these allocate storage int i; int N = 20; char prompt[] = "Enter an integer:"; int A[MAX_SIZE]; int* pBArray; int BSize; RGBa background = {0xff, 0xff, 0xff, 0x0};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.