Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starting Code: import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; public class Assembler { static String asmFileName = RectL.asm; static String

image text in transcribedStarting Code:

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; public class Assembler { static String asmFileName = "RectL.asm"; static String symbolFileName = "symbols.txt"; static String destFileName = "dest.txt"; static String compFileName = "comp.txt"; static String jumpFileName = "jump.txt"; static HashMap symbolTable = new HashMap(); static ArrayList rom = new ArrayList();//An arraylist acting as the instruction memory public static void main(String[] args) throws FileNotFoundException { //initialize symbol table, comp, dest, jump tables initTable(symbolFileName, symbolTable); printTable(symbolTable); String outFileName = getOutputFileName(asmFileName); //first pass: generate pure code and labels fistPass(asmFileName); //second pass: translate line by line and save to the output file secondPass(outFileName); } /***************************************************************************************** * fistPass: read the asm file. Ignore all non-codes. * Populate the instruction memory (the arrayList rom) with pure instructions * Also extract labels and add to the symbol table * ***************************************************************************************/ private static void fistPass(String asmFile) { } /***************************************************************************************** * secondPass: Translate the instructions in the rom one by one and save to the outFile * ***************************************************************************************/ private static void secondPass(String outFile) { } /***************************************************************************************** * getOutputFileName: get output hack file name from asm file name * @param "asmFile.asm" * @return "asmFile.hack" * ***************************************************************************************/ private static String getOutputFileName(String asmFile) { return asmFile.substring(0, asmFile.indexOf('.')) + ".hack"; } /************************************************************ * printTable: print the hashmap * */ private static void printTable(HashMap map) { Iterator itr = map.keySet().iterator(); String key = ""; while(itr.hasNext()) { key = itr.next(); System.out.println(key + "\t" + map.get(key)); } } /***************************************************************************** * initTable: initialize the given HashMap with contents from the given file * The file should have two column. The first column is the key, * second column is the value * @param -String fileName * @param -HashMap map * ******************************************************************/ private static void initTable(String fileName, HashMap map) throws FileNotFoundException { File file = new File(fileName); Scanner sc = new Scanner(file); while(sc.hasNext()) { map.put(sc.next(), sc.next()); } } }
Spring 2017 CPS210 Assignment 5: Assembler Implementation Task: Implement the Hack assembler. The assembler should take a Hack Assembly Language Program (.asm) as input, translate it into Hack Machine Program and save it as the same name with different extension (.hack) Test your code with provided asm file and the Assembler. The provided Assembler allows you to compare the hack file your assembler produced with the correct machine program Submission Pack the following files in one zip file and submit to Blackboard Documentation.pdf All source files It's a group assignment, so only one member in the group needs to submit. The Documentation.pdf should contain the following contents AT LEAST Workload division for group members. If your name and workload were not documented, you will not receive any points. As long as you have your own workload share, you will receive the same points as others Instruction on how to run the assembler. The instruction should be detailed, assuming that the reader knows nothing about your code, and nothing about how to run your program Modules description: If you assembler is implemented in several modules, describe each one, especially their interface (argument, output, etc.) Credit & Grading: 40 points in total 1. 2. Assembler: 30 points, from average of peer grading score. Grading activity: 10 points, from the grading activity Spring 2017 CPS210 Assignment 5: Assembler Implementation Task: Implement the Hack assembler. The assembler should take a Hack Assembly Language Program (.asm) as input, translate it into Hack Machine Program and save it as the same name with different extension (.hack) Test your code with provided asm file and the Assembler. The provided Assembler allows you to compare the hack file your assembler produced with the correct machine program Submission Pack the following files in one zip file and submit to Blackboard Documentation.pdf All source files It's a group assignment, so only one member in the group needs to submit. The Documentation.pdf should contain the following contents AT LEAST Workload division for group members. If your name and workload were not documented, you will not receive any points. As long as you have your own workload share, you will receive the same points as others Instruction on how to run the assembler. The instruction should be detailed, assuming that the reader knows nothing about your code, and nothing about how to run your program Modules description: If you assembler is implemented in several modules, describe each one, especially their interface (argument, output, etc.) Credit & Grading: 40 points in total 1. 2. Assembler: 30 points, from average of peer grading score. Grading activity: 10 points, from the grading activity

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

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 401(k) feature?

Answered: 1 week ago