CSE 2421 LAB 6: C and Assembly Mixed Code
IMPORTANT: READ THESE INSTRUCTIONS AND FOLLOW THEM CAREFULLY.
Objectives:
Copyright By PowCoder代写 加微信 powcoder
· combining C language with assembler language programs
· debugging and extending existing C language code
· first x86-64 experience
· correctly using memory addressing in assembler
· correctly using different size registers
REMINDERS and GRADING CRITERIA:
· This is an individual lab. No partners are permitted
· Every lab requires a Readme file (for this lab, it should be called lab6Readme – use this name, with either a .pdf or .doc or .docx extension so Carmen will accept it.). This file must include the following:
· Disclaimer:
THIS IS THE README FILE FOR LAB 6.
BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I HAVE PERFORMED ALL
OF THE WORK TO DETERMINE THE ANSWERS FOUND WITHIN THIS FILE MYSELF WITH
NO ASSISTANCE FROM ANY PERSON OTHER THAN THE INSTRUCTOR OF THIS COURSE
OR ONE OF OUR UNDERGRADUATE GRADERS. . I UNDERSTAND THAT TO DO OTHERWISE
IS A VIOLATION OF OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY.
· 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 program.
· 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 (even by a minute – or heaven forbid, less than a minute late), you will receive 75% of your earned points for the designated grade as long as 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 crashing, using the following command: % make
LAB DESCRIPTION
1. Required file names: lab6main.c, lab6.s, Makefile. You do not have to create a .h file.
1. Create your lab6main.c file by copying your file, then make the following changes:
1. insert a prototype before main() that looks like this:
long sum( long a [], int count);
1. use the given main.c code to call the sum function.
1. Create (or update the existing lab6.s) so that sum function return the sum of the array. The sum function must be written in Assembly.
1. The output of your program should print the sum of the array
1. You must create a Makefile where all will have 2 targets: lab6 and lab6.zip.
In lab6.zip you include lab6main.c, lab6.s, and the Makefile.
1. You can compile the code as follows:
gcc lab6.s lab6main.c -no-pie -o lab6
gcc lab6.s lab6main.c -o lab6
REQUIREMENTS
1. You must use correct stack frame procedures
2. You must use all (needful) x86-64 directives
3. You must use the correct suffix for all data types.
4. You must use correct memory addressing modes
5. You must use correct caller/callee saved register conventions
6. You must include the certification header in your lab6.s file (it should already be in your lab6main.c file).
7. You must comment your code!
HELPFUL SUGGESTIONS
1. Don’t forget to use tui reg general when in gdb to see register values.
2. You can use next in gdb when you want do not want to go in to the code of the function being called (printf, for example).
3. You can use step in gdb when you want do want to go in to the code of the function being called.
4. The gdb instruction x/12xb $rdi would show you twelve 1-byte values starting at the address in register rdi. Rather than $rdi, you can use a specific memory address.
5. The general form of this instruction is:
x/[NUM][SIZE][FORMAT] where
NUM = number of objects to display
SIZE = size of each object (b=byte, h=half-word, w=word, g=giant (quad-word))
FORMAT = how to display each object (d=decimal, x=hex, o=octal, etc.)
If you don’t specify SIZE or FORMAT, either a default value, or the last value you specified in a previous ‘print’ or ‘x’ command is used.
6. You can reference http://csapp.cs.cmu.edu/public/docs/gdbnotes-x86-64.pdf for several other very helpful gdb instructions for x86-64 use.
7. You may inspire from the code in the slides about the sum function. Notice that in the slides, the sum function only calculate the sum. In this lab the sum function print strings and also calculates the sum.
LAB SUBMISSION
You must submit all your lab assignments electronically to Carmen in .zip file format.
· 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 two distinct ways. Your code must work in both ways to receive points.
1. Your lab6main.c/lab6.s code combination will be tested using the make command. So go back and review the spreadsheet for that lab.
2. Your lab6.s file will be used as a library function and called by a standard version of the lab6main.c program. As long as you follow the System V ABI standards and have your parameters in the correct order, all should be good.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com