COMP1521 2020T2 Q4 · 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 practice_q4.s , a MIPS assembler program that reads 1 number and then prints it.
Add code to practice_q4.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 = 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 practice_q4.s 10 20 25 55 1521 mipsy practice_q4.s 20 22 42 1521 mipsy practice_q4.s 100 100 1521 mipsy practice_q4.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.
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.