Docsity

Integer and Floating-Point Representation in Computer Architecture, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
1. Please search for the following:
• Computer Arithmetic
1. The Arithmetic and Logic Unit
An arithmetic-logic unit is the part of a central processing unit that carries out
arithmetic and logic operations on the operands in computer instruction words.
In some processors, the ALU is divided into two units: an arithmetic unit (AU) and a logic
unit (LU). Some processors contain more than one AU -- for example, one for fixed-point
operations and another for floating-point operations.
In computer systems, floating-point computations are sometimes done by a floating-
point unit (FPU) on a separate chip called a numeric coprocessor.
[1] Hanna, K. T. (2021b, August 9). arithmetic-logic unit (ALU). WhatIs.
https://www.techtarget.com/whatis/definition/arithmetic-logic-unit-ALU
2. Integer Representation
1. Sign-Magnitude Representation
• This is one of the simplest ways to represent integers in binary. In this system:
o Sign bit: The leftmost bit represents the sign, where 0 is for positive numbers, and 1
is for negative numbers.
o Magnitude bits: The remaining bits represent the absolute value (magnitude) of the
number.
Example (8-bit representation):
o +5 in sign-magnitude would be: 00000101
o -5 in sign-magnitude would be: 10000101
2. Twos Complement Representation
• This is the most common way to represent signed integers in binary. It resolves some
problems with sign-magnitude, such as having two representations for zero.
• In this system:
o The leftmost bit still represents the sign (0 for positive, 1 for negative), but negative
numbers are represented by inverting all bits of the positive number and then adding
1.
Example (8-bit representation):
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Integer and Floating-Point Representation in Computer Architecture and more Assignments Computer Architecture and Organization in PDF only on Docsity!

  1. Please search for the following:
  • Computer Arithmetic 1. The Arithmetic and Logic Unit An arithmetic-logic unit is the part of a central processing unit that carries out arithmetic and logic operations on the operands in computer instruction words. In some processors, the ALU is divided into two units: an arithmetic unit (AU) and a logic unit (LU). Some processors contain more than one AU -- for example, one for fixed-point operations and another for floating-point operations. In computer systems, floating-point computations are sometimes done by a floating- point unit (FPU) on a separate chip called a numeric coprocessor. [1] Hanna, K. T. (2021b, August 9). arithmetic-logic unit (ALU). WhatIs. https://www.techtarget.com/whatis/definition/arithmetic-logic-unit-ALU 2. Integer Representation 1. Sign-Magnitude Representation
  • This is one of the simplest ways to represent integers in binary. In this system: o Sign bit : The leftmost bit represents the sign, where 0 is for positive numbers, and 1 is for negative numbers. o Magnitude bits : The remaining bits represent the absolute value (magnitude) of the number. Example (8-bit representation): o +5 in sign-magnitude would be: 00000101 o - 5 in sign-magnitude would be: 10000101 2. Twos Complement Representation
  • This is the most common way to represent signed integers in binary. It resolves some problems with sign-magnitude, such as having two representations for zero.
  • In this system: o The leftmost bit still represents the sign (0 for positive, 1 for negative), but negative numbers are represented by inverting all bits of the positive number and then adding

Example (8-bit representation):

o +5 in twos complement would be: 00000101 o To find - 5:

  1. Write +5: 00000101
  2. Invert the bits: 11111010
  3. Add 1: 11111011 (This is - 5 in twos complement). 3. Range Extension
  • Range extension is about increasing the number of bits to represent larger numbers.
  • In twos complement, sign extension is used when increasing the bit-width of a signed number. o You extend the sign bit (leftmost bit) of the number to maintain its value. Example : o Convert 4-bit +3 (which is 0011) to 8-bit: 00000011. o Convert 4-bit - 3 (which is 1101) to 8-bit: 11111101. Twos Complement Range : o For n bits, the range of integers represented is from - 2^(n-1) to 2^(n-1) - 1. Example (with 4-bit): o Range: - 8 to + o For 8-bit: - 128 to +127. 4. Fixed-Point Representation
  • Fixed-point representation is used for representing fractional numbers in binary.
  • A fixed number of bits are reserved for the integer part, and a fixed number of bits are reserved for the fractional part. Example : o Let’s say you have an 8-bit system with 4 bits for the integer part and 4 bits for the fractional part. o The binary number 1010.1101 represents: ▪ Integer part: 1010 = 10 in decimal. ▪ Fractional part: .1101 = 0.8125 in decimal.

o +5 (00000101) + +3 (00000011): ▪ Result: 00001000 (which is +8). o +5 (00000101) + - 3 (10000011): ▪ Result: 00000010 (which is +2).

  • In Twos Complement Representation : o Addition : Simple binary addition, including the sign bit. If the result overflows beyond the bit-width, it is discarded. o Subtraction : Subtracting is handled by adding the twos complement of the number being subtracted. ▪ To subtract, negate the second number and then add. Examples : o +5 (00000101) + +3 (00000011): ▪ Binary sum: 00001000 (which is +8). o +5 (00000101) - - 3 (take the twos complement of 3, i.e., 11111101): ▪ Binary sum: 00001010 (which is +8). Overflow : o Overflow occurs if the result of addition or subtraction falls outside the representable range for the given bit width. o In twos complement, overflow happens when the result’s sign bit is incorrect: ▪ Adding two positive numbers results in a negative result (incorrect). ▪ Adding two negative numbers results in a positive result (incorrect). 3. Multiplication and Division
  • In Sign-Magnitude Representation : o Multiplication : Multiply the magnitudes of the two numbers, then determine the sign of the result by XORing the sign bits. If the signs are different, the result is negative. o Division : Divide the magnitudes, and again, determine the sign of the result based on the sign bits. Example (8-bit): o +5 (00000101) × +3 (00000011): ▪ Multiply magnitudes: 5 × 3 = 15

▪ Result: 00001111 (which is +15).

  • In Twos Complement Representation : o Multiplication : Binary multiplication follows the same rules as unsigned binary multiplication but considers the sign bit to determine whether the result is positive or negative. ▪ The Booth's Algorithm is commonly used for efficient multiplication in hardware. Example : o +5 (00000101) × - 3 (11111101): ▪ Binary product: 11111011 (which is - 15). o Division : Similar to multiplication, the sign of the result is determined by the XOR of the signs of the operands. Division can be done through repeated subtraction or by using more complex algorithms like restoring and non-restoring division methods. Example : o +15 (00001111) ÷ - 3 (11111101): ▪ Binary quotient: 11111101 (which is - 5). Handling Overflow in Multiplication and Division : o For multiplication, overflow occurs if the product exceeds the bit-width of the result. o In division, overflow occurs if the divisor is zero (division by zero error) or if the result exceeds the allowable range for the bit-width. [3] Libretexts. (2021, July 14). 1.6: Integer Arithmetic. Engineering LibreTexts. https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Introduction_ To_MIPS_Assembly_Language_Programming_(Kann)/01%3A_Introduction/1.06%3A_Integer_Arithm etic **4. Floating-Point Representation
  1. Principles of Floating-Point Representation** A floating-point number has three main components:
  2. Sign (S) : A single bit indicating whether the number is positive (0) or negative (1).
  3. Exponent (E) : A set of bits representing the exponent that scales the significand by a power of 2 (in binary floating-point systems).
  1. Double-Precision (64-bit) Floating Point : o Total bits : 64 o Sign bit (S) : 1 bit o Exponent (E) : 11 bits o Mantissa (M) : 52 bits (with an implicit leading 1) The exponent is stored with a bias of 1023, meaning the actual exponent value is: Eactual=Estored−1023E_{\text{actual}} = E_{\text{stored}} - 1023Eactual=Estored− 1023 Example: o For the same number - 6.75, the process would be similar but with greater precision due to the larger mantissa. [4] GeeksforGeeks. (2024d, August 29). Floating Point Representation Basics. GeeksforGeeks. https://www.geeksforgeeks.org/floating-point-representation-basics/ **5. Floating-Point Arithmetic
  2. Addition and Subtraction** Floating-point addition and subtraction involve several steps to ensure numbers are aligned correctly before the operation is performed:
  • Step 1: Align the Exponents To add or subtract two floating-point numbers, their exponents must first be made equal. The number with the smaller exponent is shifted to the right until its exponent matches the larger one. This can cause a loss of precision if bits in the mantissa are shifted out. Example : 1.110×102+1.001×1011.110 \times 10^2 + 1.001 \times 10^11.110×102+1.001× Shift the smaller number (1.001 × 10^1) to align the exponents: 0.1001×1020.1001 \times 10^20.1001× Now, add the significands: (1.110+0.1001)×102=1.1011×102(1.110 + 0.1001) \times 10^2 = 1.1011 \times 10^2(1.110+0.1001)×102=1.1011×
  • Step 2: Add or Subtract the Mantissas Once the exponents are aligned, add or subtract the mantissas (or significands).
  • Step 3: Normalize the Result If the result is not in normalized form, shift the bits so that there is a single non-zero digit to the left of the decimal point, and adjust the exponent accordingly.
  • Step 4: Round the Result Floating-point numbers are represented with a fixed number of bits, so the result might need to be rounded to fit within the available bits. The IEEE standard defines several rounding modes, the default being "round to nearest." Precision Loss : Addition or subtraction of numbers with widely differing magnitudes can lead to a loss of precision because the smaller number may be shifted out entirely when aligning the exponents. For example: 1.0000001×106+1.01.0000001 \times 10^6 + 1.01.0000001×106+1. After aligning the exponents, the smaller number becomes too small to affect the result: 1.0000001×106+0=1.0000001×1061.0000001 \times 10^6 + 0 = 1.0000001 \times 10^61.0000001×106+0=1.0000001× 2. Multiplication and Division
  • Multiplication : Multiplication of floating-point numbers involves multiplying the significands and adding the exponents: N1=(−1)S1×M1×2E1,N2=(−1)S2×M2×2E2N_1 = (-1)^{S_1} \times M_1 \times 2^{E_1}, \quad N_2 = (-1)^{S_2} \times M_2 \times 2^{E_2}N1=(−1)S1×M1×2E1,N2=(−1)S2×M2×2E The result of multiplication is: N1×N2=(−1)S1⊕S2×(M1×M2)×2(E1+E2)N_1 \times N_2 = (-1)^{S_1 \oplus S_2} \times (M_ \times M_2) \times 2^{(E_1 + E_2)}N1×N2=(−1)S1⊕S2×(M1×M2)×2(E1+E2) o Sign : The result’s sign is determined by XORing the signs of the two operands. o Exponent : The exponents are added. o Mantissa : The mantissas are multiplied. After multiplying the mantissas, the result may need to be normalized (shifted if necessary) and then rounded to fit the available bits.
  • Division : Division is similar to multiplication, but instead of adding the exponents, they are subtracted: N1÷N2=(−1)S1⊕S2×(M1÷M2)×2(E1−E2)N_1 \div N_2 = (-1)^{S_1 \oplus S_2} \times (M_1 \div M_2) \times 2^{(E_1 - E_2)}N1÷N2=(−1)S1⊕S2×(M1÷M2)×2(E1−E2) The result is normalized and rounded similarly to multiplication.
  • Handling Special Values : The standard defines how special values like infinity, zero, and NaN (Not a Number) are represented and how arithmetic operations involving these values should behave: o Infinity : Operations involving positive or negative infinity follow predictable rules, such as: ▪ ∞ + ∞ = ∞ ▪ ∞ - ∞ = NaN (undefined result) ▪ 1 / ∞ = 0 o NaN : NaN is used to represent the result of undefined operations, like 0/0 or ∞ - ∞. Once a NaN appears in an arithmetic operation, the result is NaN. [5] Parthasarathi, R. (n.d.). Floating Point Arithmetic Unit – Computer Architecture. https://www.cs.umd.edu/~meesh/411/CA-online/chapter/floating-point-arithmetic- unit/index.html