Skip to content

Commit

Permalink
Implement writeIf() in CodeWriter.java
Browse files Browse the repository at this point in the history
  • Loading branch information
VipinindKumar committed Aug 25, 2017
1 parent ca5367b commit adec9f8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CodeWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,21 @@ public void writeGoto(String label) {
// Write Assembly code for the if-goto command
public void writeIf(String label) {
try {
// pop top-most value from stack
out.write("@SP");
out.newLine();
out.write("M = M - 1");
out.newLine();
out.write("A = M");
out.newLine();
out.write("D = M");
out.newLine();

// jump to the label, if the value is not equal to 0
out.write("@" + label);
out.newLine();
out.write("D;JNE");
out.newLine();

}
catch (IOException e) {
Expand Down

0 comments on commit adec9f8

Please sign in to comment.