COMP1521 2020T3 Q4 · MIPS控制流
COMP1521 2020T3 Q4 · 9 marks · MIPS
知识点: MIPS控制流(MASM-C) · 次: 双变量while · 难度: 基础
Topic: MIPS control flow · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html
一句话 / Summary: 读数直到low≥high输出low-high
You have been given 20t3final_q4.s ,
a MIPS assembler program that reads one number and then prints it.
Add code to 20t3final_q4.s to make it equivalent to this C program:
// COMP1521 20T3 final exam Q4 C reference
// print low - high
#include <stdio.h>
int main ( void ) {
int low = 0 ;
int high = 100 ;
while ( low < high ) {
int x ;
scanf ( "%d" , & x );
low = low + x ;
high = high - x ;
}
printf ( "%d \n " , low - high );
return 0 ;
}
In other words, it should read numbers until
low is greater or equal to high ,
and print low - high .
For example:
1521 mipsy 20t3final_q4.s
10
20
25
10
1521 mipsy 20t3final_q4.s
1
2
4
8
16
32
26
1521 mipsy 20t3final_q4.s
100
100
1521 mipsy 20t3final_q4.s
10
10
10
10
10
0
No error checking is required.
Your program can assume its input contains only integers, oner per line.
Your program can assume these integers will result in the program terminating.
You can assume the value of any expressions 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.
🤖 Online-judge contract: a complete MIPS program (run with mipsy). Read integers from stdin as specified; print ONLY the final integer result + newline. Startlow=0, high=100; whilelow < highread an intx,low += x; high -= x. Then printlow - high.
Examples (input → expected) are shown as sample tests below.
样例
10 20 25
10
50 50
0
100
100