Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I would like some guidance or hints on how to make this project happen: 1

ID: 3665106 • Letter: H

Question

Hello, I would like some guidance or hints on how to make this project happen:

1. Write an MIPS32 assembler using java.

2.The assembler will be able to correctly translate the instructions included in the presentation "Instruction Set Architecture" covered in classs.

3.The assembler does not need to translate pseudo instructions.

4.It does not need to resolve externals references.

5.The input file will be an ascii file with one instruction per line.

6.The program will recognize comments at the end of the line.

7. The output file will be an ascii file having one binary instruction per line in binary format.

I do not wish for the answers nor complete project, I just want to learn or get help on how to start. I would appreciate it greatly.

Explanation / Answer

Import java.util.Scanner;

Import java.io.*;

Public class Assembler {

  Public static void main(String args[]){

    try{

    String file= new String("input.txt");

    BufferedReader reader = new BufferedReader(new FileReader(file));

Int count = 0;

    String lines;

while((lines = reader.readLine()) != null)

{ count++; }

    System.out.println("number of lines in program = "+count);

    // pass one; scan for operands /

       System.out.println("Pass One: ");

    /* set up the operand table */

      String[][] operands = newString[count][3];

      BufferedReader reader2=newBufferedReader(newFileReader(file));

      String line=null;

      Int index=4095;

      Int i=0;

      String operand;

      while((line=reader2.readLine()) != null){

        if((line.length()) <= 4)

          operand = " ";

        else

        { operand=line.substring(5);}

        String bin= Integer.toBinaryString(index);

        String dex= Integer.toString(index);

        operands[i][0]=dex;

     operands[i][1]=operand;

        operands[i][2]=bin;

        index--;

        i++;

      }

      /*test print it out*/

      Int j=0;

      System.out.println("Index "+"Operand "+"Binary");

      while(j < count){

        System.out.print(operands[j][0]);

        System.out.print(" ");

        System.out.print(operands[j][1]);

        System.out.print(" ");

        System.out.println(operands[j][2]);

        j++;}

      

// pass two; scan for the opcodes //   

      System.out.println("Pass Two: ");

      

      /* create opcode table */

    String [] [] opcodes= newString[][]{

      {"0000", "LODD"},

      {"0001", "STOD"},

      {"0010", "ADDD"},

      {"1110", "ADDI"},

      {"0011", "SUBD"},

      {"0100", "JPOS"},

      {"0101", "JZER"},

      {"0110", "JUMP"},

      {"0111", "LOCO"},

      {"1000", "LODL"},

      {"1001", "STODL"},

      {"1010", "ADDL"},

      {"1011", "SUBL"},

     {"1100", "JNEG"},

     {"1101", "JNZE"},

     {"1111000000000000", "PSHI"},

     {"1111001000000000", "POPI"},

     {"1111010000000000", "PUSH"},

     {"1111011000000000", "POP"},

      {"1111100000000000", "RETN"},

      {"1111101000000000","SWAP"},

      {"11111100","INSP"},

      {"11111110", "DESP"}};

           

    /* get the opcode */

    BufferedReader reader3= newBufferedReader(newFileReader(file));

    BufferedWriter writer =       newBufferedWriter(newFileWriter ("output.txt"));

    String opcode;

    String codeBits="0000";

    intk=0;

    while((line=reader3.readLine()) != null)

    { if((line.length()) < 4){

     opcode=line.substring(0,3);}

    else

{opcode=line.substring(0,4);}

      System.out.print(opcode);

      System.out.print(" ");

     

        /* loop through opcode table*/

        for(inth=0; h<23; h++){

          if(opcode.equals(opcodes[h][1])){

            codeBits=opcodes[h][0];}

         

        }

          System.out.println(codeBits);

          /* write binary equivalents to new file*/

          writer.write(codeBits);

          

        

       String opBits = operands[k][2];

       k++;

        writer.write(opBits);

         writer.newLine();

      

    }

    writer.close();

    reader.close();

}

  }

      catch(Exception e){

System.out.println("STOP! An error has been found.");}

  }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote