OlveraeUNSW
返回题目列表
COMP1521

COMP1521 2022T3 Q2 · MIPS基础翻译

COMP1521 2022T3 Q2 · 10 marks · MIPS
知识点: MIPS基础翻译(MASM-B) · 次: 乘法 · 难度: 基础
Topic: MIPS basics · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html

一句话 / Summary: 读2数输出a²+b²


You have been given 22t3final_q2.s ,
a MIPS assembler program that reads a number
and then prints the number.

Add code to 22t3final_q2.s ,
so that it is equivalent to this C program:

// // // // // // // // DO NOT CHANGE THIS FILE! // // // // // // // //
// COMP1521 22T3 ... final exam, question 2
// Modify 22t3final_q2.s so that its behaviour
// matches the following C code.

#include <stdio.h>

int main ( void ) {
int a , b ;

scanf ( "%d" , & a );
scanf ( "%d" , & b );

printf ( "%d \n " , a a + b b );

return 0 ;
}

In other words:

It should read two numbers and print the sum of their squares.

For example:

1521 mipsy 22t3final_q2.s
3
4
25
1521 mipsy 22t3final_q2.s
6
5
61
1521 mipsy 22t3final_q2.s
5
6
61
1521 mipsy 22t3final_q2.s
42
42
3528

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

Your solution must not be in C , C++ , Python , or any other language.

No error checking is necessary or required.

样例

stdin
3
4
期望输出
25
stdin
6
5
期望输出
61
stdin
5
6
期望输出
61
mipsy
14