编程辅导 C C++ Java Python MIPS Processing 网络家教 在线辅导

编程家教 远程写代码 Debug 讲解答疑 课后答疑 不是中介,本人直接答疑

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

Systems and Architecture (AE1SYS) Assembly Programming 
1. Write a program in MIPS32 assembly language which reads a number
n from
the console, and prints out the factorial of
n:
n! = n· (n - 1)· (n - 2) · · · 2· 1:
The procedure in Java, given n, might look like:
int f = 1;
for(int i = 1; i <= n; i++){
f = f * i;
}
(15 marks)
2. Implement a program which prompts user two integers inputs
x, y from the
console and calculate the following expression in signed 32-bit arithmetic:
x2 + 9y2 + 6xy - 6x - 18y + 9
Note that you are NOT allowed to use pseudo-instructions with overflow
checking for the calculation (i.e. you can not use
mulo). If an overflow occurs
during any step of the calculation, you should print an error message instead,
and stop the program.
Hint: You could simplify the expression before calculation. Please remember
to test your program with a range of different inputs, e.g.
x = 2; y = 3;
x = -3; y = 4; x = 1 000; y = 150 000. . .
(25 marks)
3. Implement the following specification of the
strchr function which, given an
ASCII character code and the starting address of a string, returns the offset
of the first occurrence of the character in the string, or
-1 if the character
cannot be found:
1

int strchr(char needle, char[] haystack){
for(int i = 0; haystack[i] != NUL; i++)
if(haystack[i] == needle)
return i;
return -1;
}
void main(void){
int offset;
char haystack[256];
char needle[2];
haystack <- read_string; // $a0 == haystack; $a1 == 256
needle <- read_string; // $a0 == needle; $a1 == 2
offset = strchr(needle[0], haystack);
if(offset >= 0)
printf("found at offset: %d", offset);
else
printf("not found");
}
To declare a char buffer[n] of n bytes, use the .space n directive in the
.data segment.
Please implement the main function above as well. Insert a comment in your
program to illustrate how you would use
strchr to calculate the length of a
string.
(25 marks)
4. In this exercise you will use the Newton-Raphson method to calculate the
positive square root of a number n 0. In summary, the method is:
x0 ≈ pn
x
i+1 =
1 2
xi + x n i 
with pn = limi!1 xi.
Since we are working with a finite representation of floating point numbers,
we can stop when the difference between
xi and xi+1 is small enough. The
following pseudo-C program illustrates the Newton-Raphson method:
// input a floating point number n
float x0 = n, x1 = 0.5 * n;
while(abs(x0 - x1) > 1e-6):
x0 = x1;
x1 = 0.5 * (x0 + n / x0);
// The square-root of n is approximately x1
2
Implement a MIPS assembly program which implements the above method
for single-precision (32-bit) floating point numbers, without using the
sqrt.s
instruction.
(35 marks)
3
  

相关推荐