CSCI 210: Lab 1

Instruction Formats & Number Conversion
Due: 11:59 PM on Sunday, February 28th

In this lab, you should learn:

  • How to convert numbers to different bases.
  • How to parse MIPS instructions

Github

All your code for this class should be stored in Github repositories that are part of the CS210 github organization. This will give me access to your code, and give you access to version control. To create a repository for this assignment, click here.

The Assignment

On the MIPS architecture, machine language instructions are encoded in 32-bit words. Below you can see the format for R-type instructions:

And the format for I-type instructions:

Write a program named Mips in Java which takes a MIPS instruction, encoded as a hexadecimal number, as its single command-line argument, and first determines if it is an R-type or an I-type instruction, and then prints each of its fields. (All R-type instructions will have an opcode of 0)

Print each field on a separate line of output. Print the opcode as a 6-bit binary value (including leading zeros if applicable), and the rs and rt fields as decimal integers. For I-type instructions, print the address in hexadecimal. For R-type instructions, print the rd, shamt, and funct in decimal.

For example:
    
java Mips 68ec871c

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

java Mips 01494020

opcode: 000000
rs: 10
rt: 9
rd: 8
shamt: 0
funct: 32
    
    

You should write code to do all of the conversions between hex, decimal and binary yourself. Do not use the java ParseInt method to do these conversions. (However, it may be a good idea to use ParseInt to check your answers.) You also should not code this as a lookup table - you need to implement algorithms to convert between hex, decimal and binary.

Handin

Make sure the final version of your code is pushed to your github repository.
C. Taylor