logo

Crowdly

Browser

Add to Chrome

ECE2071 - Systems programming - S1 2025

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

View this question

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 i$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.

View this question

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

Convert the following MIPS instructions in the code above into machine code. Write your answers clearly in the boxes provided. Note that Bit 31 is the most significant bit and Bit 0 is the least significant bit of the machine code representing the instruction.

(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

View this question

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:

  1. 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).

  1. The histogram class should have a method named clear, that clears the histogram statistics.

  1. 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.

  1. 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

  1. All data attributes of the class should be private.

View this question

Consider the C program below and then answer the following questions.

Image failed to load

  1. Describe what the function compute_array does. (2 marks)
  2. The program output is 0 6 14 19. Explain the meaning of the output. (2 marks)
  3. Explain why the statement free(array); is required at the end of the main function. (1 mark)

View this question

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:

  1. You may also use whatever editor/test environment you like to write your solution.

  2. Your code MUST be submitted as a .txt file below BEFORE the end of the test
  3. Your .txt file should be named as q7_studentID.txt, eg q7_12345678.txt

  4. You should use good programming practices

View this question
A hash function is a function that maps any arbitrary data into a fixed-size value within a specified range. The values returned by a hash function are called hash values, or “hashes”. Hash functions are used in a wide variety of applications, including encryption and data integrity.

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:

  1.  A pointer to character (string_1) representing a C string 
  2.  An integer (starting_value) greater than 0
and returns an integer according to the process outlined below:

  • 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.

For example: string_hash("Melbourne", 5) should return a value of 20160.

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:

  1. You may also use whatever editor/test environment you like to write your solution.

  2. Your code MUST be submitted as a .txt file below BEFORE the end of the test
  3. Your .txt file should be named as q8_studentID.txt, eg q8_12345678.txt

  4. You should use good programming practices

View this question

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. 

  • Assume that the byte is stored in 0x. 
  • Store the byte in $t0 and the answer in $a0.

View this question

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;

    }

}

View this question

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:

Image failed to load: Standard MIPS datapath, showing PC, instruction memory, instruction breakdown bit by bit, register and ALU

Your architecture needs to support a basic set of operations, namely:

  • add
  • bqz (branch if greater than 0)
  • Load Word
  • Store Word

Your architecture should have 8 registers available, which should include a PC, a Stack Pointer, a Return Address, a zero register, and 4 general purpose registers.

  1. Propose a structure (format) for these instructions, based on the MIPS I and R type instruction. 
  2. Draw a datapath, without pipelining, that will support these instructions. 
  3. Explain how you have adapted each block from the standard MIPS datapath shown above to create your new system.
  4. Justify how the changes you have made minimise the hardware required to deliver the design specifications.

View this question

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome