Lab 1 - Bit level operations

Intro to Computer Architecture
Spring, 2018
Due:  February 19 (midnight)

The assignment is to write Java or C programs to solve the following problems.  When you have completed the programs, put them into a directory, and submit the contents of the directory electronically using handin.

1.  On the MIPS architecture, machine language instructions are encoded in 32-bit words.  The format for instructions which access memory consists of four fields, as shown below:

MIPS I format

Write a program which takes a MIPS instruction, encoded as a hexadecimal number, as its single command-line argument, and extracts these four fields.  Print each one on a separate line of output.  Print the opcode as a 6-bit binary value (including leading zeros if applicable), the rs and rt fields as decimal integers, and the address in hexadecimal.  For example,

input:

java Mips 68ec871c

or

./mips 68ec871c

output:

opcode:  011010
rs: 7
rt: 12
address:  871c


2.  Write a Java program with one command-line argument, an integer expressed in decimal.  The program should print the number in both decimal and hexadecimal, then reverse the hex digits in the number and print it again in both decimal and hexadecimal.  Perform the reversal at the binary level, not by applying string operations.  For example,

input:

java Reverse -5

or

./reverse -5

output:

x (base 10):  -5
x (base 16):  fffffffb
x reversed (base 10):  -1073741825
x reversed (base 16):  bfffffff

input:

java Reverse 934892812

output:

x (base 10):  934892812
x (base 16):  37b9550c
x reversed (base 10):  -1068131469
x reversed (base 16):  c0559b73