601.229 (S23): 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

  1. Write the representation of the number 43 in base 16, base 10, base 8, base 6, and base 2.
  2. On an 8-bit computer, what is the sum of unsigned 208 + 53?, and what is the difference of signed 103 - 24?
  3. Write what -5 would be on a 4-bit and an 8-bit system.
  4. Show how to calculate 1.250 + 3.375 and 1.250 * 3.375 using floating point.
  5. How are 32 bits broken down in IEEE-754?

Q2. Bitwise Operators

  1. Write the results of arithmetic and logical executions of -113 >> 1, where -113 is an 8 bit value.
  2. What is the fastest way to compute 16 * 13? (Hint: don't use multiplication.)
  3. Determine 43 | 13, 43 & 13, 43 ^ 13, and ~43 (assume operands are unsigned 8 bit.)

Q3. Basic Assembly Questions

  1. 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?
  2. How, why, and when do you align the stack pointer?
  3. What are caller and callee saved registers?
  4. Write a local loop, and the line which calls it in main, that sums all the values from 0-9, given #define N 9
  5. 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:

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.