COMP1521 2022T3 Q10 · MIPS大数
COMP1521 2022T3 Q10 · 10 marks · MIPS
知识点: MIPS大数(MASM-X) · 次: 字符串/任意精度 · 难度: 进阶
Topic: MIPS advanced (bignum) · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html
一句话 / Summary: 大整数加法与乘法任意精度
You have been given 22t3final_q10.s ,
a MIPS assembler program that reads a line of input and then prints 42.
Add code to 22t3final_q10.s
to evaluate the line as an arithmetic expression.
and print its value.
The arithmetic expression will contain
only positive integers
addition ( '+' ) operator and multiply ( '*' ) operators.
The integers may be arbitrarily large;
except they must fit on a line of less than 10,000 characters.
Partial marks will be given for solutions which handle only
only positive integers and addition but not multiplication.
There are no marks for approaches which
handle only smaller integers;
for example, those small enough to be represented in only 32 or 64 bits and stored in a register.
There are no marks for approaches which use floating point arithmetic or other methods
to produce approximate results.
For example:
1521 mipsy 22t3final_q10.s
982451653961748941472882027*452390477
202133905243937086663174722891174767
1521 mipsy 22t3final_q10.s
2100000000000000000000000000000000000000000000000000000000000000000000000000+34
200000000000000000000000000000000000000000000000000000000000000000000000012
No error checking is required.
Your program can assume it is given exactly one line of input.
Your program can assume this line is made up of only these 12 characters: 0123456789+*
You can assume the line contains less than 10,000 characters.
Your program can assume that these characters form a valid arithmetic expression.
Your solution must be in MIPS assembler only.
You are not permitted to use floating point operations or registers.
🤖 Write MIPS (mipsy). Read one line: an arithmetic expression of positive integers with+and(binds tighter; only the 12 chars0123456789+*; line < 10000 chars; integers arbitrarily large). Print the exact value. No floating point.
Verified on the sandbox (official sample solution), cross-checked against a BigInt oracle, and reproduces the official examples.
样例
982451653*961748941*472882027*452390477
202133905243937086663174722891174767
2*100000000000000000000000000000000000000000000000000000000000000000000000000+3*4
200000000000000000000000000000000000000000000000000000000000000000000000012
2+3
5