Exam 1 Practice Questions
Exam 1 Practice Questions
These questions are designed to aid your review of the material covered by the first exam. They are not representative of the difficulty, type, or length of the questions on the exam.
In all questions, assume signed integers use two’s complement representation.
Q1. Number Representation
Write the representation of the number 43 in base 16, base 10, base 8, base 6, and base 2.
On an 8-bit computer, what is the sum of unsigned
208 + 53
?, and what is the difference of signed103 - 24
?Write what
-5
would be on a 4-bit and an 8-bit system.Show how to calculate
1.250 + 3.375
and1.250 * 3.375
using floating point.How are 32 bits broken down in IEEE-754?
Q2. Bitwise Operators
Write the results of arithmetic and logical executions of
-113 » 1
, where-113
is an 8 bit value.What is the fastest way to compute
16 * 13
? (Hint: don’t use multiplication.)Determine
43 | 13
,43 & 13
,43 ^ 13
, and~43
(assume operands are unsigned 8 bit.)
Q3. Basic Assembly Questions
What are the steps that happen after you run gcc on a .c program? What does the output after each step look like, and what are their file extensions?
How, why, and when do you align the stack pointer?
What are caller and callee saved registers?
Write a local loop, and the line which calls it in
main
, that sums all the values from 0-9, given#define N 9
In AT&T syntax, what is the order of arguments for these instructions, and where are the results stored?
addq %r9, %r10
movl $FFFF0000, %esi
cmpl %eax, %eax
Q4. x86-64 Assembly Programming
Write an x86-64 assembly language function called swapInts
which swaps the values of two int
variables. The C function declaration for this function would be
void swapInts(int *a, int *b);
Hints:
- Think about which registers the parameters will be passed in
- Think about what register(s) would be appropriate to use for temporary value(s)
- Consider that
int
variables are 4 bytes (32 bits), and use an appropriate operand size suffix.
Important: Your function should follow proper x86-64 Linux register use conventions. Be sure to include the label defining the name of the function.
Q5. x86-64 Assembly Programming
Consider the following C function prototype:
void str_tolower(char *s);
The str_tolower
function modifies a C character string so that each
upper case letter is converted to lower case.
Show an x86-64 assembly language implementation of this function. Note that the ASCII codes for upper case letters are in the range 65–90, and the ASCII codes for lower case letters are the range 97–122. Characters that aren’t letters should not be modified.