OlveraeUNSW
返回题目列表
COMP1521

COMP1521 2022T2 Q2 · 位运算(MIPS)

COMP1521 2022T2 Q2 · 10 marks · MIPS
知识点: 位运算(MIPS)(BIT) · 次: 循环 · 难度: 中等
Topic: Bitwise / data representation · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html

一句话 / Summary: Q1的MIPS版本


You have been given 22t2final_q2.s , a MIPS assembler program that
reads an integer and then prints 42.

Add code to 22t2final_q2.s so that it prints
the amount of zero bits in the integer that was read in.

In other words, it should behave the same as final_q1 .

For example:

1521 mipsy 22t2final_q2.s
0
32
1521 mipsy 22t2final_q2.s
1
31
1521 mipsy 22t2final_q2.s
100000
26
1521 mipsy 22t2final_q2.s
-1
0

Your program can assume its input only contains only 1 integer.

Your program can assume that the integer will fit in a MIPS register .

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.


🤖 Write MIPS (mipsy). Read one integer, print the number of 0 bits in its 32-bit representation.

Verified on the sandbox AND cross-checked against an independent oracle (official examples included).

样例

stdin
0
期望输出
32
stdin
1
期望输出
31
stdin
100000
期望输出
26
mipsy
14