Try   HackMD

Quiz1 of Computer Architecture (2021 Fall)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
General Information

  • You are allowed to read lecture materials.
    • That is, an open book exam.
  • You shall not disclose your answer during the quiz.
  • Each answer has 5 points.
  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    09:10 ~ 10:20AM on Oct 5, 2021
  • Fill Google Form to answer

Problem A

Two's Complement is the standard for representing signed integers:

  • The most significant bit (MSB) has a negative value; all others have positive values (same as unsigned)
  • Binary addition is performed the same way for signed and unsigned
  • The bit representation for the negative (additive inverse) of a two's complement number can be found by:
    • flipping all the bits and adding 1 (i.e.-x = ~x + 1).

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

The above "number wheel" showing the relationship between 4-bit numerals and their Two's Complement interpretations is shown on the right:

  • The largest number is 7 whereas the smallest number is -8
  • There is a nice symmetry between numbers and their negative counterparts except for -8

This section is designed as a conceptual check for you to determine if you conceptually understand and have any misconceptions about this topic. Please answer Yes / No to the following questions:

  1. Is it possible to get an overflow error in Two's Complement when adding numbers of opposite signs?
  • A01 = ?
  1. If you interpret a
    N
    bit Two's Complement number as an unsigned number, would negative numbers be smaller than positive numbers?
  • A02 = ?
  1. If you interpret an
    N
    bit Bias notation number as an unsigned number (assume there are negative numbers for the given bias), would negative numbers be smaller?
  • A03 = ?

Problem B

Arithmetic overflow occurs when the result of a calculation can't be represented in the current encoding scheme (i.e., it lies outside of the representable range of values), resulting in an incorrect value.

  • Unsigned overflow: the result lies outside of
    [UMin,UMax]
    ; an indicator of this is when you add two numbers and the result is smaller than either number.
  • Signed overflow: the result lies outside of
    [TMin,TMax]
    ; an indicator of this is when you add two numbers with the same sign and the result has the opposite sign.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  1. Find the largest 8-bit unsigned numeral c (answer in HEX) such that c + 0x80 causes NEITHER signed nor unsigned overflow in 8 bits.
  • B01 = ?
  1. Find the smallest 8-bit numeral c (answer in HEX) such that c + 0x71 causes signed overflow, but NOT unsigned overflow in 8 bits.
  • B02 = ?

Problem C

According to IEEE 754 Floating Point Standard, the value of a real number can be represented in scientific binary notation as:

Value=(1)sign×Mantissa2×2Exponent=(1)S×1.M2×2Ebias

The binary representation for floating point values uses three fields:

  • S: encodes the sign of the number (0 for positive, 1 for negative)
  • E: encodes the exponent in biased notation with a bias of
    2w11
  • M: encodes the mantissa (or significand, or fraction) – stores the fractional portion, but does not include the implicit leading 1.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  1. Let’s say that we want to represent the number 3145728.12510 (broken down as
    221+220+23
    ). Is it enough to represent this number single precision floating point? (Please answer Yes / No)
  • C01 = ?
  1. What is the decimal value of float 0x80000000? (Answer with leading + and -)
  • C02 = ?
  1. What is the decimal value of float 0xFF94BEEF? (Answer with leading + and -)
  • C03 = ?
  1. What is the decimal value of float 0x41180000? (Answer with leading + and -)
  • C04 = ?
  1. What is the smallest positive value that can be stored using a single precision float? Answer in HEX value. (video: How to Calculate Smallest Float Value in IEEE 754 Standard (Single Precision))
  • C05 = ?
  1. What is the smallest positive normalized value that can be stored using a single precision float?
  • C06 = ?
  1. What is the decimal value of float 0xFF800000? (Answer with leading + and -)
  • C07 = ?
  1. What is the decimal value of float 0x421E4000? (Answer with leading + and -)
  • C08 = ?

Problem D

Floating Point Mathematical Properties

  • Not associative:
    (2+250)2502+(250250)
  • Not distributive:
    100×(0.1+0.2)100×0.1+100×0.2
  • Not cumulative:
    225+1+1+1+1225+4

If x and y are variable type float, will the expression (x + 2 * y) - y == x + y always be evaluated as true? (Please answer Yes / No with explanation.)

D01 = ?


Problem E

Compute the decimal result of the following arithmetic expressions involving 6-bit Two's Complement numbers as they would be calculated on a computer. Do any of these result in an overflow? Are all these operations possible?

  1. Input: 0b100011 + 0b111010
  • E01 = ?
  1. Input: 0xFF − 0xAA
  • E02 = ?
  1. Input: 0x3B + 0x06
  • E03 = ?

Problem F

  1. How do you write the bitwise exclusive-nor (XNOR) operator in C program?
  • F01 = ?
  1. Given x as an unsigned integer, please use bitwise operators and +, -, == to check if x is a power of 2. Write down the expression in C without any branches (i.e., if, else, ? :, do, while, for, goto)
  • F02 = ?
  1. The following function absf returns absolute value of a single precision float. What is the value of F03? Answer in HEX.
#include <stdint.h>
float absf(float x) {
  uint32_t mask = F03;
  union {
    uint32_t i;
    float f;
  } u = {.f = x};
  u.i &= mask;
  return u.f;
}
  • F03 = ?