Coursework for Tutorial 2


Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due


Coursework for Tutorial 2
Computer Architecture II:
November 5, 2024

1 Assignment

Task #1 Consider the following C code snippet. SubsetSums computes the sum for all the subsets of consecutive numbers between initial and final. Translate the C code in RISC-1, following the same logic and the calling convention agreed in class. First produce an unoptimised version of the codes with NOPs. Then see whether it can be optimised and/or give justification for where it can’t. For the printing of numbers to output, you can assume the existence of an external function printNum that takes as input an integers (following our calling convention) and prints it to the standard output. Finally, modify the C code so that it can count the number of register overflows and underflows the code execution provokes, as well as the total number of function calls it performs. Assuming a full implementation with 8 register banks, and that before main is called 2 banks are already occupied, how many overflows and underflows does the code with initial = 1, and final = 10 triggers? Provide the C code, screenshot of its result and an explanation of the implementation.
#include <stdio.h>
void subsetSums(int l, int r, int sum )
{
// Print current subset sum
if (l > r) {
printf("%d ", sum);
return;
}
// Subset sum including l
subsetSums(l + 1, r, sum + l);
// Subset sum excluding l
subsetSums(l + 1, r, sum);
return;
}
int main()
{
int sum = 0;
int initial = 1;
int final = 3;
subsetSums(initial, final,sum);
return 0;
}
Task #2
Consider the following C code that computes the sum of the first N positive integers using
recursion:
#include <stdio.h>
int sumNrecursion(int N)
{
if(N)
return(N+sumNrecursion(N-1));
else
return(N);
}
int main()
{
printf("%d\n",sumNrecursion(100));
return 0;
}
Translate the above code in RISC-1, using the same computational logic and optimising delayed jumps, if and where possible. Assuming a full ISA implementation with 8 register banks, and 2 register banks already allocated before the main function is called, how many register overflows and register underflows would the running of the above code trigger? Explain your answer.

2 Instructions

  • For the coding tasks, submit the source code files. For Task1 also submit screenshot proof of the results you obtain on the input sequences provided. The register bank explanation can be either hand-drawn or done electronically, but must be readable. Submit everything in a single zip file.
  • Due date: November 24 @ 12.59pm. Strictly no late submissions.
  • This tutorial will count toward 10% of your final grade. Each task will count toward 50% of the overall tutorial score. Tasks 1 and 2 will be evaluated according to the rubric provided.

发表评论

电子邮件地址不会被公开。 必填项已用*标注