← Back to problems
UNSW COMP1521 · medium

COMP1521 2022T3 Q5 — Bitwise / data representation

COMP1521 2022T3 Q5 · 10 marks · MIPS Topic: Bitwise / data representation · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html

Summary: MIPS version of Q4

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

Add code to 22t3final_q5.s so that it returns the length of the longest sequence of consecutive bits set to 1 in the supplied 32 bit integer.

In other words, it should behave the same as the previous question.

mipsy input is signed, so it won't accept some of the input we used in the last question. For example, mipsy won't accept as 4294967295 as input. We can get the same bit pattern (0xFFFFFFFF) by using -1 as input. This doesn't affect the code you need to write.

For example:

305419896 == 0x12345678 1521 mipsy 22t3final_q5.s 305419896 4 0 == 0x00000000 1521 mipsy 22t3final_q5.s 0 0 4 == 0x00000004 1521 mipsy 22t3final_q5.s 4 1 15 == 0x0000000F 1521 mipsy 22t3final_q5.s 15 4 -1 == 0xFFFFFFFF 1521 mipsy 22t3final_q5.s -1 32 -1431655766 == 0xAAAAAAAA 1521 mipsy 22t3final_q5.s -1431655766 1 268566401 == 0x1001FF81 1521 mipsy 22t3final_q5.s 268566401 10

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 program can assume that MIPS will accept the integer as valid input.

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 length of the longest run of consecutive 1-bits in its 32-bit representation.

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

MIPS (mipsy)