mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
Fix return translation
This commit is contained in:
+18
-2
@@ -75,17 +75,24 @@ string translateCall(string name, int args) {
|
||||
|
||||
string translateReturn() {
|
||||
stringstream output;
|
||||
string cleanupLabel = "cleanup$ret" + generateRandomLabel(3);
|
||||
string endLabel = "end$ret" + generateRandomLabel(3);
|
||||
|
||||
output << "@LCL" << endl;
|
||||
output << "D=A" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@END_FRAME" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
output << "@RETURN_ADDR" << endl;
|
||||
output << "M=D" << endl;
|
||||
output << "@5" << endl;
|
||||
output << "D=A" << endl;
|
||||
output << "@RETURN_ADDR" << endl;
|
||||
output << "M=M-D" << endl;
|
||||
output << "A=M" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@RETURN_ADDR" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
output << "@ARG" << endl;
|
||||
output << "D=M" << endl;
|
||||
@@ -108,6 +115,8 @@ string translateReturn() {
|
||||
output << "D=M" << endl;
|
||||
output << "@1" << endl;
|
||||
output << "D=D-A" << endl;
|
||||
output << "A=D" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@THAT" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
@@ -115,6 +124,8 @@ string translateReturn() {
|
||||
output << "D=M" << endl;
|
||||
output << "@2" << endl;
|
||||
output << "D=D-A" << endl;
|
||||
output << "A=D" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@THIS" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
@@ -122,6 +133,8 @@ string translateReturn() {
|
||||
output << "D=M" << endl;
|
||||
output << "@3" << endl;
|
||||
output << "D=D-A" << endl;
|
||||
output << "A=D" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@ARG" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
@@ -129,11 +142,14 @@ string translateReturn() {
|
||||
output << "D=M" << endl;
|
||||
output << "@4" << endl;
|
||||
output << "D=D-A" << endl;
|
||||
output << "A=D" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "@LCL" << endl;
|
||||
output << "M=D" << endl;
|
||||
|
||||
output << "@RETURN_ADDR" << endl;
|
||||
output << "0;JMP" << endl;
|
||||
output << "D=M" << endl;
|
||||
output << "D;JMP" << endl;
|
||||
|
||||
return output.str();
|
||||
}
|
||||
Reference in New Issue
Block a user