OlveraeUNSW
返回题目列表
COMP1521

COMP1521 2020T3 Q1 · MIPS基础翻译

COMP1521 2020T3 Q1 · 10 marks · MIPS
知识点: MIPS基础翻译(MASM-B) · 次: 表达式求值 · 难度: 基础
Topic: MIPS basics · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html

一句话 / Summary: 读2数输出(x+y)*(x-y)


You have been given 20t3final_q1.s ,
a MIPS assembler program that reads one number and then prints it.

Add code to 20t3final_q1.s to make it equivalent to this C program:

// COMP1521 20T3 final exam Q1 C reference

// print (x + y) * (x - y)

#include <stdio.h>

int main ( void ) {
int x , y ;

scanf ( "%d" , & x );
scanf ( "%d" , & y );
printf ( "%d \n " , ( x + y ) * ( x - y ));

return 0 ;
}

In other words, it should read two numbers,
x and y ,
and print (x + y) * ( x - y) .

For example:

1521 mipsy 20t3final_q1.s
5
8
-39
1521 mipsy 20t3final_q1.s
6
5
11
1521 mipsy 20t3final_q1.s
5
6
-11
1521 mipsy 20t3final_q1.s
42
42
0

No error checking is required.

Your program can assume its input always contains two integers, and only two integers.

Your program should print one and only one line of output.

This line of output should contain one integer, a newline, and nothing else.

You can assume the value of the expression can be represented as a signed 32 bit value.

In other words, you can assume overflow/underflow does not occur.

Your solution must be in MIPS assembler only.

Your solution must be in 20t3final_q1.s .

样例

stdin
5
8
期望输出
-39
stdin
6
5
期望输出
11
stdin
5
6
期望输出
-11
stdin
42
42
期望输出
0
mipsy
14