Question
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 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
For form for all assembly lines read 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)
Notes:
*Do not create these classes in a package.
*Turn in only your Java source files.
*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 (e.g. $s5) to its numeric equivalent (e.g. 21).
Required Main Class:
Assembler
Required Input:
Lines of assembler code, separated with newlines, followed by a line with HALT.
Required Output:
Your output should look something like the following example. It should include your name.
OUTPUT SHOULD READ
Assembler - 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.
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