Looking for ECE2071 - Systems programming - S1 2025 test answers and solutions? Browse our comprehensive collection of verified answers for ECE2071 - Systems programming - S1 2025 at learning.monash.edu.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Represent the following 16-bit signed integer based on 2's complement standard in base 10 (decimal). You must show your steps in detail and write your answer in the space provided below. How would the decimal representation of the given binary sequence change if the negation standard was switched from 2's complement to 1's complement?
1001 0101 0000 1000
Write a MIPS assembly language program that loads register $a0 with a 32-bit sequence. Your program should then reverse the order of the bits in $a0 and place the answer in register $a1. The program should then terminate in an infinite loop.
For example:
If $a0 = 0x00000001, then the result in $a1 should be 0x80000000
If $a0 = 0x80000000, then the result in $a1 should be 0x00000001
If $a0 = 0xC0008000, then the result in $a1 should be 0x00010003
Note that you are only allowed to use instructions listed in the MIPS reference sheet provided along with this
question in your program. Write your answer in the space provided below.
Consider the following MIPS assembly code which implements a FOR loop to find the sum of all the elements of an array of 10 integers, of which the base address is loaded in register $a0. The address of each instruction is mentioned next to the respective instruction.
Instruction Address | Instruction |
0x80010014 | addi $t0, $zero, 10 |
0x80010018 | li $t1, 0 |
0x8001001C | li $v0, 0 |
0x80010020 | loop: beq $t0, $t1, exit |
0x80010024 | lw $t2, 0($a0) |
0x80010028 | add $v0, $v0, $t2 |
0x8001002C | addi $t1, $t1, 1 |
0x80010030 | addi $a0, $a0, 4 |
0x80010034 | j loop |
0x80010038 | exit: addi $a0, $a0, -40 |
(a) beq $t0, $t1, exit
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
(b) j loop
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
This problem is adapted from Programming in C++ by Michael D. Adams. You can access the textbook via Google Books.
In this question, you will develop a Histogram class to create histograms (counting how many values fall in each of a number of intervals). The class should satisfy the following:The constructor should be passed a single argument that is a vector of doubles containing the bounds of the histogram bins. The elements of the vector can be assumed to be strictly increasing (each value is greater than the previous value). For example, instantiating the class with the vector: {0.0, 3.14, 20.0, 42.42, 69} would create a histogram with four bins, corresponding to the intervals: [0, 3.14), [3.14, 20), [20. 42.42), [42.42, 69).
The histogram class should have a method named clear, that clears the histogram statistics.
The histogram class should have a method named update, that is passed a single argument; a double that represents a new data point to add to the histogram. You can assume all data passed to this method will be within the range of the histogram bins.
The histogram class should have a method named display, that prints each bin’s range, followed by the number of values that fall into that bin.
For example, if the histogram was initialised with the vector : {0.0, 3.14, 20.0, 42.42, 69} and the update method was called with the following numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, then calling the display method would print the following:
[0, 3.14): 3
[3.14, 20): 7
[20, 42.42): 3
[42.42, 69): 2
All data attributes of the class should be private.
Consider the C program below and then answer the following questions.
Image failed to load
A circular linked list (where the last node points back to the first node) is used to represent a group of people sitting around a table. However, some random people at the table are found to be infected. If they are infected, they will infect the people sitting directly next to them after 1 hour.
void infection_propagation(struct Node *Header)
Write a C function infection_propagation that will take the address of the first node of a circular linked list as input argument, where each node in the linked list of type struct Node and represents a person seated at the table. The data member within the node is equal to 1 if the respective person is infected and 0 otherwise. Your function must propagate the infection around the table by calculating the number of infected people at each hour, and stop when all people at the table are infected.struct Node {
int data;
struct Node *next;
}
Note:Part 1 (5 marks)
int string_hash (char* string_1, int starting_value)
Write a C function string_hash that takes in the following input arguments:
Step 1: Find the smallest prime number that is greater than starting_value and stores this as the current prime value (current_prime)
Step 2: For each character in the string (except the terminating NULL character), calculate the product of the ASCII value of the current character and current_prime.
Step 3: Add the result of the calculation in Step 2 to the accumulator value (accumulator), which is initialized as zero at the start of the function.
Step 4: Calculate the sum of accumulator and current_prime, and then assign the result as the new value of accumulator.
Step 5: Find the next smallest prime number that is greater than the current_prime and assign this as the new value of current_prime.
Step 6: Repeat steps 2-5 until all non-NULL characters in the string have been considered.
Step 7: Return the value of accumulator upon exit.
Part 2 (5 marks)
Write a C code inside the main function that performs the following activities:
Scan a string (string_1) and integer (starting_value) as input from the user
Call the hash_string function written in part 1, using string_1 and starting_value as the inputs
Scan a string as input from the user, representing a filename
Opens the file and appends an new line to the file which contains string_1, starting_value, and the accumulator in the following format:
<string_1><whitespace><starting_value><whitespace>-<whitespace><accumulator>
Note:Write a MIPS program that can count the number of times a 1 appears in a single byte.
For example if the byte was A3 (1010 0011) the program would return 4.
From the C code create an equivalent MIPS program:
int main() {
int example_array [5];
example_array[0]= 3;
for(int i=1; i<=5; i++){
example_array[i] = example_array[i-1]*2 -4;
}
}
In this question you will propose a design for an 8 bit architecture, based on the 32 bit MIPS architecture and datapath that you have studied.
The standard 32-bit datapath is below for your reference:
Your architecture needs to support a basic set of operations, namely: