From 943f164d7c3647bdbcc6839f41a3c16ffe72cded Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Tue, 29 Aug 2017 03:57:50 +0000 Subject: [PATCH] Change the style of labels and goto statements inside a function --- CodeWriter.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/CodeWriter.java b/CodeWriter.java index 216d78c..98101ba 100644 --- a/CodeWriter.java +++ b/CodeWriter.java @@ -668,13 +668,12 @@ public void writeFunction(String funcName, String nLocals) { out.newLine(); // while(n > 0) - out.write("(LOOP" + i + ")"); - out.newLine(); + writeLabel(funcName + "$LOOP"); out.write("@n"); out.newLine(); out.write("D = M"); out.newLine(); - out.write("@END_LOOP" + i); + out.write("@" + funcName + "$END_LOOP"); out.newLine(); out.write("D;JLE"); out.newLine(); @@ -689,14 +688,10 @@ public void writeFunction(String funcName, String nLocals) { out.newLine(); // goto LOOP - out.write("@LOOP" + i); - out.newLine(); - out.write("0;JMP"); - out.newLine(); + writeGoto(funcName + "$LOOP"); // (END_LOOPi) - out.write("(END_LOOP" + i + ")"); - out.newLine(); + writeLabel(funcName + "$END_LOOP"); i++; }