lab6.md 11/20/2019
1 / 4
CSE2421 Lab6 (20 Points)
Assigned: Friday, November 22th
Early Due Date: Saturday, November 30th by 11:30PM
Due: Monday, December 2nd, by 11:30PM
Objectives:
Combining C language with assembly 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). This file must include the
following:
Your name.
Explain why truncating a value, sign extending it back and then comparing it to the original value
can determine whether or not the value fits in the number of bit specified.
You should aim to always hand in an assignment on time or early. If you are 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 will receive an
automiatic 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, lab6assem.s, Makefile. You do not have to create a .h file.
2. You will be given three files: lab6main.partial.c, lab6assem.partial.s and a Makefile. You must
add a small amount of code to the lab6main.partial.c file to complete your lab6main.c file. You
must add all other code to the lab6assem.partial.s file to complete your lab6assem.s file. The
Makefile is included so that you can create your lab6 executable. What needs to be added to the .c
file are a couple of function prototypes close to the top of the file and function calls to bit_check_d()
lab6.md 11/20/2019
2 / 4
and bit_check_f() at the appropriate places in the code. Assume that bit_check_d() prints out all
bits of a value declared as a double and bit_check_f() prints out all bits of a value declared as a float.
Each of these two programs should be passed a single parameter. You are responsible for determining
the type of the variable to be passed to both of these functions.
3. The executable created prints out the bits that represent either a IEEE754 value (in either single or
double precision) or an integer value (in 1, 2, 4 or 8 bytes).
4. The main() program prompts for the type of value (either integer or float). These values should all be
interpreted as signed values.
5. main() then prompts for the size of the value.
6. main() calls the appropriate function bit_check(), bit_check_f(), or bit_check_d() to print out
the bit pattern of the value.
7. There is one function that must be modified that is partially written (and is included in lab6assem.s) in
x86-64 assembler. There are two other functions that must be completely written in x86-64 assembler.
However, if you think through the problem, you should see that bit_check_f() and bit_check_d()
can be identical programs except one will print 32 bits and the other will print 64. The algorithm
needed to determine whether any particular bit is a 0 or 1 is part of your assignment; however, it
should be easy to figure out from the comments in the code. Ask questions if you don’t see what it’s
suggesting you do.
8. An example of the program output is supplied in a file called lab6.output. 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, if needed.
5. You must use correct caller/callee saved register conventions, if needed.
6. You must comment your code.
7. Any filenames that include the phrase “partial” will NOT be accepted and you will get a 0 grade on the
assignment.
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 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 do want to go in to the code of the function being called.
lab6.md 11/20/2019
3 / 4 4. The gdb instruction x/2w $rdi will show you two (4-byte) words starting at the address in register
%rdi. Besides $rdi, you can use a specific memory address.
5. The general form of the above 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 other very helpful gdb
instructions for x86-64 use.
Lab submission:
Always be sure your linux prompt reflects the correct directory or folder where all of your files to be submitted
reside. If you are not in the directory with your files, the following will not work correctly.
You must submit all your lab assignments electronically to Carmen in .zip file format. The usage of the zip
command is as follows:
$ zip
where is the name of the file you want zip to add all of your files to, and is a list of the file(s) that make up the lab. Remember that you have to be at the correct location (the
designated directory) for the command to be able to find your files-to-submit.
For lab6, the zip command would look like this:
$ zip lab6 lab6main.c lab6assem.s Makefile lab6Readme
Once you execute the command, you should find a file in your lab6 directory called lab6.zip. This is the file
that must be submitted to Carmen.
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. She or he will always build/compile your code using
gcc -ansi –pedantic -g
and run the executable generated by that command.
lab6.md 11/20/2019
4 / 4
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 point. No exceptions!