| CSCI 567, Fall 2006 | Assignment 10 |
int factorial(int N)
{
if (N==0) return 1;
return N * factorial(N-1);
}
Unfortunately, both the value N! and the computation time grow much too quickly to use as a demonstration of linkage stack operation (12! is the largest factorial which can be held in a 32-bit register). On the other hand, computation size and time of a sum grow only linearly, so we will compute sum(N) (also written N?) instead of N! in this assignment. Knuth, in The Art of Computer Programming, Volume 1, calls this the termial function, with algorithm:
int termial(int N)
{
if (N==0) return 0;
return N + termial(N-1);
}
Requirements -
The termial of 100 is 5050 The termial of 1000 is too large.termget will call termial once for each N, to calculate N?. You will have to use the same calling sequence that termial uses to call itself.
//logonidA JOB
//S1 EXEC HLASMCEG,EPARM='LIST,MAP,XREF'
//ASM.SYSIN DD *
TermGet CSect ,
TermGet AMode 24 Needed for X-macros
TermGet RMode 24
Print NoGen
.
. loop to read N and calculate N?
.
End TermGet
*PROCESS RENT
Termial CSect
*
*********************************************************************
*
* This routine calculates the termial value of the integer passed.
*
* Input: R0 has number whose termial is to be calculated
*
* Output: R15 has the sum N?
*
.
.
.
End ,
//GO.INPUT DD DSN=T90MES1.C567.AS10(N),DISP=SHR
You should not overestimate the resources required. In particular, if it is expanded, the linkage stack size should not be greater than will be needed.
Turn in the output from the job.