mirror of
https://github.com/avinal/The-VM-to-HACK-Translator.git
synced 2026-01-10 07:08:32 +05:30
cleaned code
This commit is contained in:
@@ -359,167 +359,6 @@ void code_writer::write_eq_lt_gt(std::string op, bool debug)
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
/*
|
||||
void code_writer::write_add(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// add" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D+M" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_sub(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// sub" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=M-D" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_neg(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// neg" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=-M" << std::endl;
|
||||
this->ins_no += 3;
|
||||
}
|
||||
|
||||
void code_writer::write_and(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// and" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D&M" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_or(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// or" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D|M" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_not(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// not" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=!M" << std::endl;
|
||||
this->ins_no += 3;
|
||||
}
|
||||
|
||||
void code_writer::write_eq(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// eq" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "A=A-1" << std::endl
|
||||
<< "D=M-D" << std::endl;
|
||||
this->ins_no += 5;
|
||||
outfile << "@" << this->ins_no + 6 << std::endl
|
||||
<< "D;JEQ" << std::endl
|
||||
<< "D=0" << std::endl;
|
||||
this->ins_no += 3;
|
||||
outfile << "@" << this->ins_no + 4 << std::endl
|
||||
<< "0;JMP" << std::endl
|
||||
<< "D=-1" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_lt(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// lt" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "A=A-1" << std::endl
|
||||
<< "D=M-D" << std::endl;
|
||||
this->ins_no += 5;
|
||||
outfile << "@" << this->ins_no + 6 << std::endl
|
||||
<< "D;JLT" << std::endl
|
||||
<< "D=0" << std::endl;
|
||||
this->ins_no += 3;
|
||||
outfile << "@" << this->ins_no + 4 << std::endl
|
||||
<< "0;JMP" << std::endl
|
||||
<< "D=-1" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
|
||||
void code_writer::write_gt(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
outfile << "// gt" << std::endl;
|
||||
}
|
||||
outfile << "@SP" << std::endl
|
||||
<< "AM=M-1" << std::endl
|
||||
<< "D=M" << std::endl
|
||||
<< "A=A-1" << std::endl
|
||||
<< "D=M-D" << std::endl;
|
||||
this->ins_no += 5;
|
||||
outfile << "@" << this->ins_no + 6 << std::endl
|
||||
<< "D;JGT" << std::endl
|
||||
<< "D=0" << std::endl;
|
||||
this->ins_no += 3;
|
||||
outfile << "@" << this->ins_no + 4 << std::endl
|
||||
<< "0;JMP" << std::endl
|
||||
<< "D=-1" << std::endl
|
||||
<< "@SP" << std::endl
|
||||
<< "A=M-1" << std::endl
|
||||
<< "M=D" << std::endl;
|
||||
this->ins_no += 6;
|
||||
}
|
||||
*/
|
||||
|
||||
void code_writer::write_init(bool debug)
|
||||
{
|
||||
if (debug)
|
||||
|
||||
Reference in New Issue
Block a user