SP 2021 CSE 2421 LAB 6: The Ghost of Lab 2
Assigned: Thursday, March 18th
Early Due Date: Monday, March 29th by noon Due: Tuesday, March 30th, by 11:30 p.m.
IMPORTANT: READ THESE INSTRUCTIONS AND FOLLOW THEM CAREFULLY.
Objectives:
– combiningClanguagewithassemblerlanguageprograms – debuggingandextendingexistingClanguagecode
– firstx86-64codingexperience
– correctlyusingdifferentsizeregisters
REMINDERS and GRADING CRITERIA:
This is an individual lab. No partners are permitted.
This is your first attempt as programming in x86-64. Start now! There will be no deadline extensions for this lab. Plan accordingly.
Every lab requires a Readme file (for this lab, it should be called lab6Readme – use only this name.). This file must be a simple text file created on stdlinux that includes the following:
∙ Disclaimer:
BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I STRICTLY ADHERED TO THE TENURES OF THE OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY.
THIS IS THE README FILE FOR LAB 6.
∙ Your name
∙ Total amount of time (effort) it took for you to complete the lab
∙ Short description of any concerns, interesting problems or discoveries encountered, or comments in general about the contents of the lab
∙ Describe how you used gdb to find work with your C language program if there were any. Include how you set breakpoints, variables you printed out, what values they had, what you found.
∙ Describe how you used gdb to find a bug in your x86-64 programs. Include details with respect to what breakpoints you set what registers you looked at and how you determined what the bug was.
∙ Did you have to jump between your C language/x86-64 language programs to fix any bugs?
You should aim to always hand an assignment in on time or early. If you are late, you will receive 75% of your earned points for the designated grade if the assignment is submitted by 11:30 pm the following day, based on the due date given above. If you are more than 24 hours late, you will receive a zero for the assignment and your assignment will not be graded at all.
Any lab submitted that does not compile/make – without errors or warnings – and run without seg
faults or exhibit any other major OS errors/faults WILL RECEIVE AN AUTOMATIC GRADE OF ZERO. No exceptions will be made for this rule – to achieve even a single point on a lab, your code must minimally build (compile to an executable) on stdlinux and execute on stdlinux without hanging or crashing, using the following command: make. A seg fault is considered crashing.
LAB DESCRIPTION
1. You will be rewriting lab2 from earlier in the semester. Required file names: bit_encode.c, create_key.s, rotate_right.s, rotate_left.s, Makefile. The file bit_encode.c will contain only the main() function; the file create_key.s will contain only a function called create_key(); the file rotate_right.s will contain only a function called rotate_right(); and the file rotate_left.s will contain only a function called rotate_left().
2. The function unsigned int create_key() is an x86-64 function that must prompt for (using the printf() function) and read in each of the 4 digits of the key (using the getchar() function) and return the 8-bit key to the calling function. You must create an 8-bit key from those 4 digits using ONLY
the bitwise OR instruction or ONLY the bitwise OR instruction and a shift instruction. For example, if the user specifies 0110, then your internal key must be 0110 0110.
Using any other operations to create the key will result in a 50-point reduction in your score for this lab.
3. The function unsigned_char rotate_right(unsigned char x) and the function unsigned char rotate_left(unsigned char x) are also x86-64 functions that must be passed a single hexadecimal value and return to the calling function that value rotated 1 position right or left, respectively.
4. You must modify your bit_encode.c file from lab2 to call each of these x86-64 functions appropriately.
5. You can remove the #ifdef PROMPT/#endif statements if you wish. If you do not remove them, then your Makefile must correctly compile your code so that prompts appear.
6. The output of your program should be exactly as described in lab 2 for bit_encode1.
7. You must create a Makefile where all will have 2 targets: bit_encode and lab6.zip.
REQUIREMENTS
1. Youmayonlyusex86-64constructsthatwehavediscussedinclass,youcanfindintheslides,
or you can find in the sample x86-64 programs posted on Piazza. Any other constructs will
invalidate your lab submission.
2. Youmustusecorrectstackframeproceduresandconventions.
3. Novaluesinthex86-64functionsofyourprogrammaystorevaluesonthestack.
4. Youmaydeclarevariablesinthemain()functionofyourprogramthatarestoredonthestack.
5. Youmustuseall(needful)x86-64directives.
6. Youmustusethecorrectsuffixforalldatatypes(instructionsandregistersizes).
7. Youmustuse4-byteregistersforthereturnvaluefromgetchar(),allcreate_key()computations
and the value create_key returns to main()
8. Youmustuse1-byteregistersforallrotate_left()androtate_right()computationsandparameter
passing.
9. Youmustusecorrectcaller/calleesavedregisterconventions.
10.You must call printf() once to prompt for the 4-bit key and getchar() for each bit of the key (i.e., 4 times) within your assembler program. You can do this with 4 separate calls to getchar() or you can get some practice at creating a loop. These C-library function calls MUST be made within your create_key() x86-64 function.
11.You must include the certification header in your .s files (it should already be in your bit_encode.c file).
12.You must comment your code!
HELPFUL SUGGESTIONS
1. Don’tforgettousetuireggeneralwheningdbtoseeregistervalues.
2. Youcanusenextingdbwhenyouwantdonotwanttogointothecodeofthefunctionbeing
called (printf, for example).
3. Youcanusestepingdbwhenyouwantdowanttogointothecodeofthefunctionbeingcalled.
4. Youcanreferencehttp://csapp.cs.cmu.edu/public/docs/gdbnotes-x86-64.pdfforseveralother
very helpful gdb instructions for x86-64 use.
LAB SUBMISSION
You must submit all your lab assignments electronically to Carmen in .zip file format. You must create your zip file from within your Makefile.
I highly recommend testing your .zip submission you’ve created prior to submission. If things are missing, your lab can not be graded, and you will receive a 0 on the lab.
NOTE:
• Your programs MUST be submitted in source code form. Make sure that you zip all the required files for the current lab (and .h files when necessary), and any other files specified in the assignment description. Do NOT submit the object files (.o) and/or the executable. The grader will not use executables that you submit anyway.
• It is YOUR responsibility to make sure your code can compile and run on CSE
department server stdlinux.cse.ohio-state.edu, without generating any errors or
warnings or segmentation faults, etc. Any program that generates errors or warnings
when compile or does not run without system errors will receive 0 points. No
exceptions!
HOW YOUR LAB WILL BE GRADED
Your lab will be tested in the following way:
1.
2. 3.
Your code will be tested similarly to how your lab2 was tested. So, go back and review the spreadsheet for that lab.
Your x86-64 code will be inspected to ensure that the requirements listed above were followed. Your readme file will be inspected for answers to the questions asked. So, don’t forget to submit it.