Ejemplo n.º 1
0
  public void generateCode(CODE code) throws CodeGenException {

    code.comment(" METHOD " + this.name);
    // save return address (r7) in word 3 of stack
    // STR R7 R6 3
    code.commentline(" save SFP R7 and initialize SP R5");
    code.add(new LC3STR(LC3regs.R7, CODE.SFP, 2));
    if (this.isEntry) {
      code.add(new LC3LEA(CODE.TMP0, code.arguments));
      code.add(new LC3STR(CODE.TMP0, CODE.SFP, 3));
    }
    code.add(new LC3ADD(CODE.SP, CODE.SFP, 3 + this.getVarCount()));
    code.commentline(" body ");
    this.body.generateCode(code);
    code.comment(" METHOD END " + this.name);
  }
Ejemplo n.º 2
0
  public void generateCode(CODE code) throws CodeGenException {
    LC3label cont = code.newLabel();

    code.comment(" MULT BEGIN ");
    code.commentline("lhs");
    this.lhs.generateCode(code);
    code.commentline("rhs");
    this.rhs.generateCode(code);

    //		 Hvis det er forkert, kald multi subroutine el. tilf¿j NOT(TMP1)!

    code.commentline("Multiplication");
    code.pop2(CODE.TMP0, CODE.TMP1);
    code.add(cont);
    code.add(new LC3ADD(CODE.TMP0, CODE.TMP0, CODE.TMP0));
    code.add(new LC3ADD(CODE.TMP1, CODE.TMP1, -1));
    code.add(new LC3BRP(cont));
    code.push(CODE.TMP0);
    code.comment(" MULT END ");
  }