Skip to content

Commit

Permalink
Neg instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
quazi-irfan committed May 5, 2017
1 parent 33373c2 commit 6249176
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 21 additions & 0 deletions TACx86Pkg/x86Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,25 @@ public static String writeInteger(String var1){

return writeIntegerTemplate;
}

public static String negTemplate(String var1, String var2) {
String negTemplate = "";
if(var2.charAt(0) == '@'){
negTemplate = negTemplate.concat("\t\tmov bx,").concat(var2.substring(1, var2.length())).concat("\n");
negTemplate = negTemplate.concat("\t\tmov ax, [bx]").concat("\n");
negTemplate = negTemplate.concat("\t\tneg ax").concat(var2).concat("\n");
} else {
negTemplate = negTemplate.concat("\t\tmov ax, ").concat(var2.substring(1, var2.length())).concat("\n");
negTemplate = negTemplate.concat("\t\tneg ax").concat("\n");
}

if(var1.charAt(0) == '@'){
negTemplate = negTemplate.concat("\t\tmov bx, ").concat(var1.substring(1, var1.length())).concat("\n");
negTemplate = negTemplate.concat("\t\tmov [bx], ax");
} else {
negTemplate = negTemplate.concat("\t\tmov ").concat(var1).concat(", ax").concat("\n");
}

return negTemplate;
}
}
12 changes: 9 additions & 3 deletions TACx86Pkg/x86Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,22 @@ else if(statement.length() > 38){
if(operator.equals("+")){
asmWriter.println(x86Templates.additionTemplate(var1,var2,var3));
} else if(operator.equals("-")){

//todo subtraction
} else if(operator.equals("*")){
asmWriter.println(x86Templates.multiplicationTemplate(var1,var2,var3));
} else if(operator.equals("/")){

// todo division
}

continue;
}

// Assignment statement #2 : x = op y
else if(statement.length() > 22 && (statement.charAt(16) == '-' || statement.charAt(16) == '+')){
else if(statement.length() > 22 && (statement.charAt(16) == '-')){
String var1 = fixBP(firstToken);
tokenizer.nextToken();
String var2 = fixBP(tokenizer.nextToken());
asmWriter.println(x86Templates.negTemplate(var1, var2));

continue;
}
Expand All @@ -151,6 +155,8 @@ else if(statement.length() > 22 && (statement.charAt(16) == '-' || statement.cha
}
} while (statement != null);

isSuccessfullyTranslated = true;

asmWriter.close();
}

Expand Down

0 comments on commit 6249176

Please sign in to comment.