public void genArithmeticExpression(ArithmeticExprNode expr) { genExpression(expr.lhs); genExpression(expr.rhs); assembly.addLine("pop ebx"); //rhs --> ebx assembly.addLine("pop eax"); //lhs --> eax switch (expr.op) { case ArithmeticExprNode.OPERATOR.ADD: assembly.addLine("add eax,ebx"); break; case ArithmeticExprNode.OPERATOR.SUB: assembly.addLine("sub eax,ebx"); break; case ArithmeticExprNode.OPERATOR.MULT: assembly.addLine("mul eax,ebx"); break; case ArithmeticExprNode.OPERATOR.DIV: assembly.addLine("div eax,ebx"); break; case ArithmeticExprNode.OPERATOR.MOD: assembly.addLine("div eax, ebx"); assembly.addLine("mov eax, edx"); //remainder is in edx break; case ArithmeticExprNode.OPERATOR.PLUS: break; case ArithmeticExprNode.OPERATOR.MINUS: break; case ArithmeticExprNode.OPERATOR.INC: assembly.addLine("inc eax"); break; case ArithmeticExprNode.OPERATOR.DEC: assembly.addLine("dec eax"); break; default: break; } assembly.addLine("push eax"); //result --> stack }
public ArithmeticExprNode makeModuloExprNode(ExprNode lhs, ExprNode rhs) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.MOD, lhs, rhs); return(node); }
public ArithmeticExprNode makeMultiplyExprNode(ExprNode lhs, ExprNode rhs) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.MULT, lhs, rhs); return(node); }
public ArithmeticExprNode makeDivideExprNode(ExprNode lhs, ExprNode rhs) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.DIV, lhs, rhs); return(node); }
public ArithmeticExprNode makeSubtractExprNode(ExprNode lhs, ExprNode rhs) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.SUB, lhs, rhs); return(node); }
public ArithmeticExprNode makeAdditionExprNode(ExprNode lhs, ExprNode rhs) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.ADD, lhs, rhs); return(node); }
public ArithmeticExprNode makePostMinusMinusExprNode(ExprNode term) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.DEC, term, null); return(node); }
public ArithmeticExprNode makePrePlusPlusExprNode(ExprNode term) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.INC, null, term); return(node); }
public ArithmeticExprNode makeUnaryMinusExprNode(ExprNode term) { ArithmeticExprNode node = new ArithmeticExprNode(ArithmeticExprNode.OPERATOR.MINUS, term, null); return(node); }