← 返回题目列表
UNSW COMP1521 · 中等

COMP1521 2020T2 Q3 · 位运算(MIPS)

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

一句话 / Summary: Q2的MIPS版本


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)