COMP1521 2022T3 Q3 · 10 marks · MIPS 知识点: MIPS控制流(MASM-C) · 次: while累加 · 难度: 基础 Topic: MIPS control flow · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html
一句话 / Summary: 读数直到和≥42输出和
You have been given 22t3final_q3.s , a MIPS assembler program that reads 1 number and then prints it.
Add code to 22t3final_q3.s to make it equivalent to this C program:
// read numbers until their sum is >= 42, print their sum
#include <stdio.h>
int main ( void ) { int sum = 0 ; while ( sum < 42 ) { int x ; scanf ( "%d" , & x ); sum += x ; } printf ( "%d \n " , sum ); return 0 ; }
In other words, it should read numbers until their sum is ≥ 42 and then print their sum.
For example:
1521 mipsy 22t3final_q3.s 10 20 25 55 1521 mipsy 22t3final_q3.s 20 22 42 1521 mipsy 22t3final_q3.s 100 100 1521 mipsy 22t3final_q3.s 10 10 10 10 10 50
No error checking is required.
Your program can assume its input contains only integers.
Your program can assume these integers sum to ≥at least 42.
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.