Back to problems
COMP1521
COMP1521 2022T2 Q2 — Bitwise / data representation
COMP1521 2022T2 Q2 · 10 marks · MIPS
Topic: Bitwise / data representation · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html
Summary: MIPS version of Q1
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).
Samples
stdin
0
expected
32
stdin
1
expected
31
stdin
100000
expected
26
mipsy
14