mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
Implement branching
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#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();
|
||||
}
|
||||
Reference in New Issue
Block a user