For this exam, you may use your textbook, your notes and assignments, your brain, and divine guidance if available. You may not use other books, other people, or Internet resources. If you get stuck, talk to Jeff Ondich, but please don't talk to anyone else about the exam.
Submit your answers on paper. For the PDP8 code in problem 1, submit your .pal file using HSP.
Your goal here is not an efficient algorithm (so, in particular, you
should not use your multiplication code from assignment 2). Your
goal is to write a correct subroutine that takes up as few words of
memory as possible. Your score will be based on correctness (8 points)
and brevity (4 points).
Execution times in micro-seconds for PDP8/E instructions
--------------------------------------------------------
Addressing mode
------------------------------------------
Instruction Indirect with
Type Direct Indirect auto-increment
--------------------------------------------------------
AND 2.6 3.8 4.0
TAD 2.6 3.8 4.0
ISZ 2.6 3.8 4.0
DCA 2.6 3.8 4.0
JMS 2.6 3.8 4.0
JMP 1.2 2.4 2.6
Opcode 7 1.2 (addressing mode irrelevant)
--------------------------------------------------------
Answer the following questions:
#include <iostream>
int factorial( int N );
int main()
{
for( int N=1; N <= 40; N++ )
cout << N << "! = " << factorial( N ) << endl;
return( 0 );
}
int factorial( int N )
{
int product = 1;
for( int i=2; i <= N; i++ )
product = product * i;
return( product );
}
When you run this code, you get correct values of N! for a while, and then you start to get incorrect values. Answer the following questions:
#include <iostream>
int main()
{
int m = 100;
int a[4];
int n = 200;
int i;
for( i=-1; i <= 4; i++ )
a[i] = i;
cout << "m = " << m << endl;
cout << "n = " << n << endl;
for( i=0; i < 4; i++ )
cout << "a[" << i << "] = " << a[i] << endl;
return( 0 );
}
Answer the following questions, which assume you are compiling and running this program on one of the Math/CS Linux machines (I tried it on codd.mathcs.carleton.edu).
A B C || f(A,B,C) =============================== 0 0 0 || 0 0 0 1 || 1 0 1 0 || 1 0 1 1 || 1 1 0 0 || 0 1 0 1 || 1 1 1 0 || 1 1 1 1 || 0