Question
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
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
The form for all assembly lines will be:
- BEQ
- LW
- SW
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.
This is what I have so far but I don't know how to link it all together. this is my first time coding in Java.
import java.util.*;
public class assemble { public static void main(String[] args) { Scanner input = new Scanner (System.in); String op0, op1, op2, op3; while (true) { op0 = input.next(); if(op0.equals("HALT")) { break; } op1 = input.next(); op2 = input.next(); op3 = input.next(); if (op0.equals("ADD")) { int binaryCode = makeR(0, regToByte(op3), regToByte(op1), regToByte(op2), 0, 100000); } if (op0.equals("AND")) { int binaryCode = makeR(0, regToByte(op3), regToByte(op1), regToByte(op2), 0, 100100); } if (op0.equals("SRL")) { int binaryCode = makeR(0, regToByte(op3), regToByte(op1), regToByte(op2), 0, 000010); } if (op0.equals("SLL")) { int binaryCode = makeR(0, regToByte(op3), regToByte(op1), regToByte(op2), 0, 000000); } if (op0.equals("ADDI")) { int binaryCode = makeI(001000, regToByte(op2), regToByte(op1), //immediate); } if (op0.equals("ANDI")) { int binaryCode = makeI(001100, regToByte(op2), regToByte(op1), //immediate); } if (op0.equals("BEQ")) { int binaryCode = makeI(000100, regToByte(op2), regToByte(op1), //immediate); } if (op0.equals("LW")) { int binaryCode = makeI(100011, regToByte(op2), regToByte(op1), //immediate); } if (op0.equals("SW")) { int binaryCode = makeI(101011, regToByte(op2), regToByte(op1), //immediate); }
} static byte regToByte (String s) { int type = 0; switch(type) {
case 1: if(s == "$ZERO") { int byteNum = 0; } break; } } int makeR(op0, rs, rt, sd, shamt, funct); int makeI(op0, rs, rt, imm); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started