Optimizing compilers sometimes examine the source code and rewrite it into something more efficient, such as:
main()
{
print( mysub( 6 ) );
}
The next example program prompts the user for an integer, reads in the integer, and prints the factorial. The SPIM console window is at right. The pseudo-code for the program is:
# main()
# {
# int a, b; // a: 0($fp), b: 4($fp)
# write("enter an int:")
# read( a );
# b = fact( a );
# write("factorial is:")
# print( b );
# }
# int fact( int n )
# {
# if ( n <= 1 )
# return 1;
# else
# return n*fact(n-1);
# }