Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write the code where it is supposed to be. Do not give me the answer as a MIPS, but a java code. The code
Please write the code where it is supposed to be. Do not give me the answer as a MIPS, but a java code. The code that I will handle have a tester which can be used to test the code and make sure that it works. Please test the code completly before giving it to me.
Code:
import java.util.Scanner; public class Assembler { private static final boolean TEST_MODE = true; public static void main(String[] args) { int count = 0; if (TEST_MODE) { testCases(); } else { System.out.println("Assembler - Your Name Here "); // Your code here System.out.println(" *** Assembly complete. Program required " + count + " words of memory."); } } private static int makeR(byte opcode, byte rs, byte rt, byte rd, byte shamt, byte funct) { int returnValue = 0; return returnValue; } private static int makeI(byte opcode, byte rs, byte rt, short immed) { int returnValue = 0; return returnValue; } private static byte regToByte(String r) { byte returnValue = 0; return returnValue; } /************************************************************* * * Test Code below * Do NOT modify * ************************************************************/ private static void testCases() { if (test_regToByte()) System.out.println("RegToByte working well "); else System.out.println("RegToByte failed "); if (test_makeR()) System.out.println("makeR working well "); else System.out.println("makeR failed "); if (test_makeI()) System.out.println("makeI working well "); else System.out.println("makeI failed "); } private static boolean test_regToByte() { boolean passedTest = true; String[] regs = { "$ZERO", "$AT", "$V0", "$V1", "$A0", "$A1", "$A2", "$A3", "$T0", "$T1", "$T2", "$T3", "$T4", "$T5", "$T6", "$T7", "$S0", "$S1", "$S2", "$S3", "$S4", "$S5", "$S6", "$S7", "$T8", "$T9" }; for (int i = 0; i
Output:
Assembler - (Your Name) *** Begin entering Assembler: ADD $v0 $v1 $zero AND $a0 $a1 $a2 ADDI $a3 $t4 -321 ANDI $t0 $t5 123 BEQ $s0 $t1 +517 LW $s1 -12 $t2 SW $s2 20 $t3 SRL $a2 $a3 3 SLL $a3 $a2 31 HALT ***: 00000000011000000001000000100000 ***: 00000000101001100010000000100100 ***: 00100001100001111111111010111111 ***: 00110001101010000000000001111011 ***: 00010010000010010000001000000101 ***: 10001101010100011111111111110100 ***: 10101101011100100000000000010100 ***: 00000000000001110011000011000010 ***: 00000000000001100011111111000000 *** Assembly complete. Program required 9 words of memory.Remember to test the code before sending it to me and make sure that the output it is the same as shown.
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: - code >rdrsrt (for codes ADD, AND) - code rdrt shift_amount (for codes SRL, SLL) - code rr rs immediate (for codes ADDI, ANDI) - BEQrsrt branch_address - LW
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