// MiniJava Program: // --------------------------------------------------------------------------- // // class Factorial{ // public static void main(String[] a){ // System.out.println(new Fac().ComputeFac(10)); // } // } // class Fac { // public int ComputeFac(int num){ // int num_aux ; // if (num < 1) // num_aux = 1 ; // else // num_aux = num * (this.ComputeFac(num-1)) ; // return num_aux ; // } // } // --------------------------------------------------------------------------- // NB: hacked to pass commandline argument as t77 // call like this: muHwI Fact3.intm 5 // fp and sp can be omitted if arguments are passed by registers SET NAME rp = t3 // if omitted a default frame size of 20 is used FCT LFactorial$main(REG t1, REG t77) = { L7: t35 <- CALL L_halloc_obj(4) t36 <- CALL L_init_obj(t35, 4) t41 <- CALL LFac$ComputeFac(t35, t77) CALL L_print(t41) JUMP L6 [L6] L6: } // Frame size can be set to 0 since // all variables are in registers FCT LFac$ComputeFac(REG t1, REG t38) FS 0 = { L9: CJUMP (t38<1) ? L3 : L4 L4: t43 <- t38 t42 <- CALL LFac$ComputeFac(t1, (t38-1)) t39 <- (t43*t42) JUMP L5 [L5] L5: t3 <- t39 JUMP L8 [L8] L3: t39 <- 1 JUMP L5 [L5] L8: }