mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-02 02:10:27 +00:00
39 lines
653 B
C++
39 lines
653 B
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
string translateLabel(string label)
|
|
{
|
|
stringstream output;
|
|
|
|
output << "(" << label << ")" << endl;
|
|
|
|
return output.str();
|
|
}
|
|
|
|
string translateGoto(string label)
|
|
{
|
|
stringstream output;
|
|
|
|
output << "@" << label << endl;
|
|
output << "0;JMP" << endl;
|
|
|
|
return output.str();
|
|
}
|
|
|
|
string translateIfGoto(string label)
|
|
{
|
|
stringstream output;
|
|
|
|
output << "@SP" << endl;
|
|
output << "M=M-1" << endl;
|
|
output << "A=M" << endl;
|
|
output << "D=M" << endl;
|
|
|
|
output << "@" << label << endl;
|
|
output << "D;JNE" << endl;
|
|
|
|
return output.str();
|
|
} |