#include “Assembler.h”
#include “SymbolTable.h”
#include
Copyright By PowCoder代写加微信 assignmentchef
using namespace std;
* Assembler constructor
Assembler::Assembler() {
// Your code here
* Assembler destructor
Assembler::~Assembler() {
// Your code here
* Assembler first pass; populates symbol table with label locations.
* @param instructions An array of the assembly language instructions.
* @param symbolTable The symbol table to populate.
void Assembler::doFirstPass(SymbolTable* symbolTable, string instructions[], int numOfInst) {
// Your code here
* Translates a set of instructions to machine code.
* @param instructions An array of the assembly language instructions to be converted to machine code.
* @param symbolTable The symbol table to reference/update.
* @return A string containing the generated machine code as lines of 16-bit binary instructions.
string Assembler::doSecondPass(SymbolTable* symbolTable, string instructions[], int numOfInst) {
// Your code here
return “”;
* Parses the type of the provided instruction
* @param instruction The assembly language representation of an instruction.
* @return The type of the instruction (A_INSTRUCTION, C_INSTRUCTION, L_INSTRUCTION, NULL)
Assembler::InstructionType Assembler::parseInstructionType(string instruction) {
// Your code here:
return NULL_INSTRUCTION;
* Parses the destination of the provided C-instruction
* @param instruction The assembly language representation of a C-instruction.
* @return The destination of the instruction (A, D, M, AM, AD, MD, AMD, NULL)
Assembler::InstructionDest Assembler::parseInstructionDest(string instruction) {
// Your code here:
return NULL_DEST;
* Parses the jump condition of the provided C-instruction
* @param instruction The assembly language representation of a C-instruction.
* @return The jump condition for the instruction (JLT, JGT, JEQ, JLE, JGE, JNE, JMP, NULL)
Assembler::InstructionJump Assembler::parseInstructionJump(string instruction) {
// Your code here:
// for example if “JLT” appear at the comp field return enum label JLT
if (instruction.find(“JLT”) != string::npos) {
return JLT;
return NULL_JUMP;
* Parses the computation/op-code of the provided C-instruction
* @param instruction The assembly language representation of a C-instruction.
* @return The computation/op-code of the instruction (CONST_0, … ,D_ADD_A , … , NULL)
Assembler::InstructionComp Assembler::parseInstructionComp(string instruction) {
// Your code here:
// for example if “0” appear at the comp field return CONST_0
if (instruction.find(“0”) != string::npos) {
return CONST_0;
return NULL_COMP;
* Parses the symbol of the provided A/L-instruction
* @param instruction The assembly language representation of a A/L-instruction.
* @return A string containing either a label name (L-instruction),
* a variable name (A-instruction), or a constant integer value (A-instruction)
string Assembler::parseSymbol(string instruction) {
return “”;
* Generates the binary bits of the dest part of a C-instruction
* @param dest The destination of the instruction
* @return A string containing the 3 binary dest bits that correspond to the given dest value.
string Assembler::translateDest(InstructionDest dest) {
// Your code here:
return “000”;
* Generates the binary bits of the jump part of a C-instruction
* @param jump The jump condition for the instruction
* @return A string containing the 3 binary jump bits that correspond to the given jump value.
string Assembler::translateJump(InstructionJump jump) {
// Your code here:
return “000”;
* Generates the binary bits of the computation/op-code part of a C-instruction
* @param comp The computation/op-code for the instruction
* @return A string containing the 7 binary computation/op-code bits that correspond to the given comp value.
string Assembler::translateComp(InstructionComp comp) {
// Your code here:
return “0000000”;
* Generates the binary bits for an A-instruction, parsing the value, or looking up the symbol name.
* @param symbol A string containing either a label name, a variable name, or a constant integer value
* @param symbolTable The symbol table for looking up label/variable names
* @return A string containing the 15 binary bits that correspond to the given sybmol.
string Assembler::translateSymbol(string symbol, SymbolTable* symbolTable) {
// Your code here:
return “0000000000000000”;
程序代写 CS代考加微信: assignmentchef QQ: 1823890830 Email: [email protected]
Reviews
There are no reviews yet.