Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description: An Assembler translates a program in symbolic assembly code into native machine code. Create a mini-Assembler for a 32-bit MIPS processor. Your program

Problem Description:

An Assembler translates a program in symbolic assembly code into native machine code. Create a mini-Assembler for a 32-bit MIPS processor. Your program should accept input lines from the user until HALT is read. With each line, translate the line into MIPS machine code. Print the total memory space needed for the completed program.

To make the parsing easier, there is one instruction per line, and each token is separated by spaces (no commas, parentheses or labels). You should convert all input to upper case. You do not need to check for illegal codes or registers. If a , , or is too large for the field, mask off the bits you need.

The form for all assembly lines will be:

  • (for codes ADD, AND)
  • (for codes SRL, SLL)
  • (for codes ADDI, ANDI)
  • BEQ
  • LW immediate
  • SW immediate

Your Assembler should accept the following subset of the complete ISA:

  • Functions: ADD, ADDI, AND, ANDI, BEQ, LW, SW, SRL, SLL
  • Registers: $zero, $v0-1, $a0-3, $t0-9, $s0-7
  • Immediates and shift amounts should be read in decimal
  • Branch addresses should be read as a decimal offset from PC+4 (positive or negative). That is, you don't need to do any address arithmetic, just use the immediate given.

Notes:

  • Do not create these classes in a package.
  • Turn in only your Java source files.
  • Despite what the example below looks like, your assembler can read and translate one line at a time. It does not need to read in the whole file first. In the example below, I cut and pasted nine lines into the running program. So you main program can be something like:
    • Until HALT
      • Read a line
      • Translate it
      • Print it
  • Printing a 32-bit binary number can be done in Java with the following:

System.out.println("***: " + String.format("%32s", Integer.toBinaryString(word)).replace(" ", "0"));

  • You may find it useful to define methods similar to the following:

int makeR(byte opcode, byte rs, byte rt, byte rd, byte shamt, byte funct)

Constructs a 32-bit integer from the component parts for an R-type instruction.

int makeI(byte opcode, byte rs, byte rt, short immed)

Constructs a 32-bit integer from the component parts for an I-type instruction.

byte regToByte(String r)

Converts a string representation of a register to its numeric equivalent. For example, if you pass in $s5, it will return 21. Why 21? Check you green sheet, bottom righthand corner).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Do Question 7 ifp, = .96 for all x.

Answered: 1 week ago

Question

abcd

Answered: 1 week ago