← Back to problems
UNSW COMP1521 · medium

COMP1521 2020T2 Q3 — Bitwise / data representation

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

Summary: MIPS version of Q2

You have been given practice_q3.s , a MIPS assembler program that reads an integer value and then prints it.

Add code to the file practice_q3.s so that it prints 1 iff the least significant (bottom) byte of value is equal to the second least significant byte, and prints 0 otherwise.

For example, given the decimal value 305419896 , which is hexadecimal 0x12345678 , practice_q3.s should print 0 , because the least significant byte, 0x78 , is not equal to the second least significant byte, 0x56 .

Similarly, given the decimal value 305419862 , which is hexadecimal 0x12345656 , practice_q3.s should print 1 , because the least significant byte, 0x56 , is equal to the second least significant byte, 0x56 .

For example:

1521 mipsy practice_q3.s 0 1 1521 mipsy practice_q3.s 1 0 1521 mipsy practice_q3.s 256 0 1521 mipsy practice_q3.s 257 1 1521 mipsy practice_q3.s 4626 1 1521 mipsy practice_q3.s 4627 0 1521 mipsy practice_q3.s 305419896 0 1521 mipsy practice_q3.s 305419862 1

Your solution must be in MIPS assembler only.

Your program can assume its input always contains one integer.

No error checking is necessary.

It is recommended, but not required, that you use bitwise operators.


🤖 Online-judge contract: a complete MIPS program (run with mipsy). Read integers from stdin as specified; print ONLY the final integer result + newline. Read one integer from stdin. Print 1 iff its least-significant byte equals its 2nd least-significant byte, else 0.

Examples (input → expected) are shown as sample tests below.

MIPS (mipsy)