Question 1 [10 Marks]
Write a program in MIPS assembly language which reads a positive integer N and prints out the following:
1 2 3 4 5 … N
Question 2 [15 Marks]
Copyright By PowCoder代写 加微信 powcoder
Implement a MIPS program which prompts user to enter two integer inputs M and N from the console, and calculate the following expression in signed 32-bit arithmetic:
8M3 24M2N + 24MN2 72N3
Note that you are NOT allowed to use pseudo-instructions with overflow checking for the calculation (e.g. you cannot use mulo). If an overflow occurs during any step of the calcu- lation, you should print an error message instead, and stop the program.
Hint: You could simplify the expression before calculation. Remember to test your program with a range of di↵erent inputs, for example: M = 3, N = 1; M = 3, N = 1; M = 10000, y = 1000; etc.
Question 3 [25 Marks]
Implement a MIPS version of the C function strncpy(), which is specified in the IEEE 1003.1-2017 Standard.
Background
The format of strncpy() is defined below:
char *strncpy(char *s1, const char *s2, size_t n); Quoted from the ISO description:
“The strncpy() function shall copy not more than n bytes (bytes that follow a NULL character are not copied) from the array pointed to by s2 to the array pointed to by s1. If the array pointed to by s2 is a string that is shorter than n bytes, NULL characters shall be appended to the copy in the array pointed to by s1, until n bytes in all are written. The strncpy() function shall return s1.”
Given the following C code snippet:
#include
#include
int main() {
char s1[10] = STRING 1;
char s2[10] = STRING 2;
int n = N;
strncpy(s1, s2, n);
printf(“%s”, s1);
Note: To execute the code snippet above, you may need to replace the RED colored content by syntactically correct C code. For example:
6 char s1[10] = “Together”;
7 char s2[10] = “Future”;
8 int n = 2;
Then the program should output
Your are required to implement the MIPS assembly code that returns EXACTLY the same result as e↵ectively calling the strncpy() function in line 10 of the code snippet above. You should not change any parts in the above code snippet, except the red colored content. No mark is awarded to this question if this requirement is not followed.
Once you execute your MIPS code, by invoking the appropriate syscall, at the QtSpim console your program should intake a single string in the following format (Px indicates Parameter x):
P1:STRING 1;P2:STRING 2;P3:N;
where the RED colored content should be replaced in the same way as the above C snippet.
For example:
P1:”Together”;P2:”Future”;P3:2;
After your code is executed based on the above input, by invoking the appropriate syscall, at the QtSpim console, your program should output the corresponding strncpy result. For the example above, the output should be:
What happens if strncpy() returns an run-time error?
At the simulator console, your program should output the following message below. Note that: you do not have to specify the error, but make sure your program generates exactly this error message whenever strncpy() generates any error message.
An error has occurred.
What happens if strncpy() returns an compile-time error? 5
My test cases will not contain inputs that lead to a compile error (or even warning). It is the job of the compiler to examine the compile error or warning, and the aim of this coursework is not writing a compiler. In other words, you can ignore the cases that cause compiler errors and warnings. They will not appear in the test cases.
1. Use the built-in gcc compiler available in our cslinux server as the standard strncpy() behavior reference. You can copy and paste the C code into cslinux and run, to obtain the referential strncpy() result. In other words, your program should output exactly the same ‘s1’ value (except errors) as the C code outputs under gcc in cslinux.
2. To access cslinux and the gcc inside, refer back to your labs in the PGA module. A manual to access cslinux via X2Go is found here. Below is a snapshot that hopefully helps you recall the usage of gcc on cslinux.
Figure 1: Demonstration of compiling and running C code on cslinux.
3. For remote students, if cslinux is unavailable, please use the OnilneGDB C compiler as the reference, similar to your PGA module practice. Kindly note that this option is only for online students.
4. Click here to refer to the formal definition of strncpy() function.
5. Feel free to post questions in Moodle Discussion Forum, or email us regarding your doubts
for clarification. Especially, with doubts in this question, contact Dr. Heng directly. 6
Evaluation
1. Out of the 25 marks for this question, TEN (10) test cases will be employed to evaluate the functionality of your program. Example test case:
Each correct answer is rewarded 2.5 marks. Each incorrect answer is rewarded 0 mark. Your output answer should follow exactly the output requirement given in this question, otherwise it would be deemed incorrect.
2. Again, unless otherwise specified, we will use the gcc compiler currently available in cslinux and onlineGDB (only for online students) as the standard strncpy() behavior reference, to evaluate your program output.
3. Good luck! Enjoy MIPS Programming. Remember to submit your coursework on time.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com