The program handin33 will only submit files in the cs33/labs/06 directory. (You should run update33 first to set up the directory and create any necessary files.)
Remember: You are encouraged to work with a partner.
In this lab, we will write C programs, use a Makefile, read from "standard in" and write to "standard out".
Each program must follow these following guidelines:
Some examples of times in 24-hour format are:
The following are some sample runs of this program. Underlined words are entries that the user typed in:
Run 1:
Enter the first time: 10:46
Enter the second time: 13:51
The difference between the times is 3 hours and 5 minutes.
Run 2 - Make sure you say "1 hour" (or "1 minute") not "1 hours" (or "1 minutes"):
Enter the first time: 13:15
Enter the second time: 14:30
The difference between the times is 1 hour and 15 minutes.
Run 3 - If the hours are 0, don't print them:
Enter the first time: 17:59
Enter the second time: 18:00
The difference between the times is 1 minute.
Run 4 - If the minutes are 0, don't print them. Note that the second time isn't always later in the day than the first time:
Enter the first time: 03:22
Enter the second time: 07:22
The difference between the times is 4 hours.
Run 5 - If there is no difference, say so:
Enter the first time: 09:29
Enter the second time: 09:29
There is no difference between the times.
Your program must prompt for and read input in the form mm/dd/yy exactly (including slashes) from the user. Then convert the month into the corresponding month name, and convert the 2-digit year into the correct 4-digit year.
You must use a switch statement (p. 368) to convert the month into the name of the month. You must use an if statement (p. 344) to convert the 2-digit year into a 4-digit year.
You should not use a variable to store the name of the month: just print each month name directly (e.g. printf("January");)
You should print out an error message if the user types in an invalid month (not between 1-12), an invalid year (not between 0-99) or types in an invalid date (depending on the month). If the year is a multiple of 4, February should have 29 days; otherwise it should have 28. Any error should result in main returning a value of 1.
The following are some sample runs of this program. Underlined words are entries that the user typed in:
Run 1:
Enter the date: 11/04/08
The date is November 4, 2008.
Run 2:
Enter the date: 12/31/08
The date is December 31, 2008.
Run 3:
Enter the date: 02/29/08
The date is February 29, 2008.
Run 4 - The function main returns 1:
Enter the date: 02/29/09
Error: Bad date entered.
Run 5: - The function main returns 1:
Enter the date: 13/29/08
Error: Bad date entered.
After running each test case, you can check that the return value is correct by typing: echo $? on the command line. $? is a special variable which stores the return value of a program after it finished executing.
Your program (called perfect.c) should calculate and the first four perfect numbers and then return the fourth perfect number. Your solution should use one for loop (p. 353) and one while loop (p. 350). There should be no input or output. You can verify your program works by typing echo $? in the terminal after the program ends. For verification, the first four perfect numbers are 6, 28, 496, and 8128, so your program should return 8128. NOTE/WARNING: Only 1 byte is displayed when you echo $? -- so if you return 8128 from your program, the terminal will only display 192. WHY?
When you are done and you are sure your program works, have gcc generate the assembly language code (gcc -S -m32 perfect.c). Edit the file perfect.s and add comments into the file that explain what is happening in the program. Do not delete any lines of that file.
You may find the x86 Assembly book on wikibooks to be a helpful resource for instructions that you can't decipher. Also, use google to track down any additional instructions you have trouble figuring out.
You can write comments in assembly by using the number sign (#). Anything from that symbol to the end of the line is a comment. For example:
#save the old base pointer and set up the new base pointer pushl %ebp #push the old base pointer onto the stack movl %esp, %ebp #set the new base pointer to be the stack pointerNote that after you edit .s file, you should still be able to compile that into a running program as follows: gcc -m32 -o perfect perfect.s (not perfect.c).