int fib( int n )
This function returns the nth fibonacci number. See
wikipedia
for more information about the the fibonacci sequence.
We are going to let fib(0)=0.
Can assume that n is a non-negative number that is less than
or equal to 9.
int sum( int n )
This function returns the sum of the numbers 0 through n.
This function can assume that n is a non-negative number that
is less than or equal to 9.
void countDownUp( int n )
This function prints the integers n through 1 to standard out
and then prints the numbers 1 through n to standard out.
This function assume that n is a non-negative number that is
less than or equal to 9.
All of the routines take a single integer in the range 0 to 9 as input
so as to simplify input for LC3.
% ./Cdriver -n 6
or
% ./Cdriver -n6
The C version of all the recursive routines will help guide the development
of the C--, MIPS, and LC3 drivers. As such it has more
requirements than the other drivers.
% ./Cdriver -n4
fib(4) = 3
sum(4) = 10
4
3
2
1
1
2
3
4
% ./Cdriver -n-5
ERROR: n = -5, n should be in range 0 to 9
% ./Cdriver -h
./Cdriver: illegal option -- h
% ./Cdriver blah
Usage: ./Cdriver -n#
% ./Cdriver -n 2
fib(2) = 1
sum(2) = 3
2
1
1
2
The output of your Cdriver executable will be compared with the output of
the reference Cdriver.public executable, which is availabe in ~cs270/public/.
(Note: You might find the getopt-example.c covered in recitation helpful).
4This set of commands should be used to compile the CMMdriver.c file and run the resulting assembly code in the MARS simulator http://courses.missouristate.edu/KenVollmar/MARS/. A copy of the MARS simulator can be found in the cs270 public directory (~cs270/public/).
% java -jar cmm.jar --patt-mips CMMdriver.c CMMdriver.s
% java -jar Mars.jar nc CMMdriver.s < four.in
fib(4) = 3
sum(4) = 10
4
3
2
1
1
2
3
4
Note that your CMM driver should generate results identical to those
generated by the Cdriver.public.
/* Hello
multi-line comment
*/
should be translated to the following:
// Hello
// multi-line comment
//
printf("fib(");
printf("%d", n);
should become the following:
cout << "fib(";
cout << n;
Also to read in an integer from standard input, use the following:
// Read in the input integer.
cin >> n;
.text
.globl main
main:
li $v0, 5 # read an integer from stdin
syscall # $v0 now contains read in integer
move $s0, $v0 # $s0 <- $v0
la $a0, SUMSTR # print "sum(" to stdout
li $v0, 4 #
syscall #
# print n to stdout
move $a0, $s0 # $a0 <- $s0 <- input number
li $v0, 1 # indicate print_int syscall
syscall
la $a0, NEWLINE # print "\n"
li $v0, 4 # indicate print_string
syscall
# HALT
li $v0, 10
syscall
.data
SUMSTR: .asciiz "sum("
NEWLINE: .asciiz "\n"
Also see notes from class (November 11 and 13) and
Appendix A.
% java -jar Mars.jar nc MIPSdriver.s < four.in
fib(4) = 3
sum(4) = 10
4
3
2
1
1
2
3
4
Note that your MIPS driver should generate results identical to those
generated by the Cdriver.public.
% ./LC3assem.public LC3driver.asm LC3driver.LC3
% ./LC3sim.public LC3driver.LC3 < LC3driver.in
fib(4) = 3
sum(4) = 10
4
3
2
1
1
2
3
4
The LC3 driver does NOT need to test that the number provided through standard input is provided in the correct format or is in the correct range.
LD R6, SP_INIT ; initialize the stack pointer
...
SP_INIT .FILL x7000 ; initial address for stack pointer
Also, LC3 does not have any traps that input integers or output integers.
You only need to be able to input integers in the range 0 through 9.
However, you will need to output integers with more than one digit.
We are providing the print_int, div10, and mod10 routines to help you print
integers to the screen and as recursive examples in LC3. They will be available in ~cs270/public/PA5-start/LC3driver-start.asm.
Cdriver.public
cmm.jar
Mars.jar
LC3assem.public
LC3sim
PA5-start/LC3driver-start.asm
You can also copy and modify files such as the Makefile from previous assignments.
You will have to take out the -std=c99 flag to make getopt work.
To figure out how to read input from the command line and from standard in see the examples given in recitation (~cs270/public/R9).
See SVN Notes for directions for setting up a subversion repository and working directory.
We STRONGLY recommend that you implement one function at a time. Start with the C functions and unit tests to ensure that the C functionality is working fully. Then complete each of the other drivers (CMMdriver, MIPSdriver, and LC3driver) one driver and one function at a time. Make sure that you can almost always compile and run something, and debug as you go.
% svn log -r HEAD:1 // must be done in subversion working directory
% svn info // must be done in subversion working directory
% svnlook tree REPOSITORY_PATH // svnlook must be issued on the machine where the repository is stored
We recommend copying the output of the above commands into an editor and
saving the result as subversion.txt.
% cd ~/CS270/
% tar cvf PA5_userid.tar PA5
% ~cs270/bin/checkin PA5 PA5_username.tar
% ~cs270/bin/SubmissionVerifier.sh PA5Full Sanity Check (procedure we will use to grade your assignment):
% cd ~/CS270/
% cp PA5_username.tar ~/Temp
% cd ~/Temp
% tar xf PA5_username.tar
% cd PA5
% make all // this should compile and run C unit tests
We will also be testing the other drivers as specified above.
We will be reading through the code comments for the code style requirements
portion of the grade.