comp1521 – Week 07 Tutorial Questions (Solution)

$ 20.99
Category:

Description

1. How is the assignment going?
Does anyone have hints or advice for other students?
2. Give MIPS directives to represent the following variables:
a. int v0;
b. int v1 = 42;
c. char v2;
d. char v3 = ‘a’;
e. double v4;
f. int v5[20];
g. int v6[10][5];
h. struct { int x; int y; } v7;
i. struct { int x; int y; } v8[4];
j. struct { int x; int y; } *v9[4];
Assume that we are placing the variables in memory, at an appropriately aligned address, and with a label which is the same as the C variable name.
3. Translate this C program to MIPS assembler.

4. Translate this C program to MIPS assembler.

5. Consider the following operation that multiplies all of the elements in a matrix by a constant factor:

This operation could be rendered in C99-standard C as

Write a function in MIPS assembly equivalent to the above C code. Assume that the arguments are placed in the $a? registers in the order given in the function definition. e.g., the function could be called as follows in MIPS:

Where M is defined as:

6. Consider the following 3-d array structure:

The cube could be implemented as an array of pointers, each of which points to a slice of the cube. Each slice of the cube is also an array of pointers, and each of those points to an array of int values.
For example, in the diagram above, the cell labelled x can be accessed as cube[0][0][1], and the cell labelled y can be accessed as cube[0][2][3].
a. Write MIPS assembler directives to define a data structure like this.
b. Write MIPS assembler code to scan this cube, and count the number of elements which are zero.
In other words, implement the following C code in MIPS.

7. For each of the following struct definitions, what are the likely offset values for each field, and the total size of the struct:

Both the offsets and sizes should be in units of number of bytes.
8. Challenge exercise, for those who have seen linked data structures in C. Consider a linked list

which could be defined in MIPS as:

Write a MIPS function that takes a pointer to the first node in the list as its argument, and returns the maximum of all of the values in the list. In other words, write a MIPS version of this C function:

You can assume that only positive data values are stored in the list.
9. If we execute the following small MIPS program:

… we observed that the first syscall displays 32768, but the second syscall displays -32768. Why does this happen?
10. FIFO queues can be implemented using circular arrays. For example:

And the C code to manipulate such a structure could be:

Assuming that the items in the queue are ints, and the following MIPS data definitions are used:

… implement the enqueue() and dequeue() functions in MIPS.
Use one of the standard function prologues and epilogues from lectures.
For all enquiries, please email the class account at cs1521@cse.unsw.edu.au
CRICOS Provider 00098G

Reviews

There are no reviews yet.

Be the first to review “comp1521 – Week 07 Tutorial Questions (Solution)”

Your email address will not be published. Required fields are marked *