AComputer Arithmatic

Embed Size (px)

Citation preview

  • 8/13/2019 AComputer Arithmatic

    1/45

    Computer Arithmetic Pada

    Computer Organization

    Computer ArithmeticRepresentasi bilangan padacomputer adalah :

    1. Sign and magnitude2. Ones Complement 3. Twos Complement

  • 8/13/2019 AComputer Arithmatic

    2/45

    ALU Inputs and Outputs

  • 8/13/2019 AComputer Arithmatic

    3/45

    Integer Representation

    Operasi menggunakan sirkuit logika dengandua nilai sinyal listrik yang di representasikan

    dengan 0 & 1 .Positive numbers stored in binarye.g. 41=00101001

    No minus signNo periodSign-MagnitudeTwos compliment

  • 8/13/2019 AComputer Arithmatic

    4/45

    Bilangan Binary Digit

    Tuliskan bilangan binary sebagai berikut : 1 = 0001 7 = 14 =

    2 = 0010 8 = 15 = 3 = 0011 9 = 16 =10000 4 = 0100 10 = 17 =

    5 = 11 = 18 = 6 = 13 = 19 = 10011

  • 8/13/2019 AComputer Arithmatic

    5/45

    Penambahan Bilangan Binary

    5 = 0101 4 = 6 =3 = 0011 5 = 2 = ---------+ ----------------+ ----------------+

    15247 bil Desimal di konversi Hexa :15247 : 16 = 952 sisanya 15 = F 952 : 16 = 59 sisanya 8 = 8 59 : 16 = 3 sisanya 11 = B 3 : 16 = 0 sisanya 3 = 3Jadi (15247 ) Des = (3B8F) Hex

  • 8/13/2019 AComputer Arithmatic

    6/45

    Konversi Desimal ke Octal ke biner

    Desimal Octal Biner 0 0 000 1 1 001

    2 2 010 3 3 4 4 5 5 6 6 7 7

  • 8/13/2019 AComputer Arithmatic

    7/45

    Konversi Desimal ke Hexa ke Biner

    Desimal Hexa Biner 0 0 0000

  • 8/13/2019 AComputer Arithmatic

    8/45

    Konversi Biner ke Octal

    1 101 000 101 = 1 5 0 5 oct

  • 8/13/2019 AComputer Arithmatic

    9/45

    Konversi Biner ke Hexa

    1 1101 1100 0101 1001 = 1 D C 5 9

  • 8/13/2019 AComputer Arithmatic

    10/45

    Representasi Binary Code Decimal (BCD)

    Desimal Biner BCD 0 0000 0000 1 0001 0001

  • 8/13/2019 AComputer Arithmatic

    11/45

    Konversi Desimal ke BCD

    (3729)Dec =

  • 8/13/2019 AComputer Arithmatic

    12/45

    Sign-Magnitude

    Bit paling kiri sign bit0 means positive

    1 means negative+18 = 00010010 -18 = 10010010

    ProblemsNeed to consider both sign and magnitude inarithmeticTwo representations of zero (+0 and -0)

  • 8/13/2019 AComputer Arithmatic

    13/45

    Pada Sistem Sign Magnitude denganBilangan 4 Bit

    Nilai negatif dinyatakan dengan mengubah Most Significant bit dari0 ke 1. Misalnya : + 5 adalah 0101 dan -5 adalah 1101 danseterusnya .BilaDalan Representasi ones coplement , nilai negatif diperolehdengan menggantikan tiap bit pada ngan positif yang sesuai.Bilangan ones complement : +7 = 0111 +0 = 0000 -1 = 1110+6 = 0110 -7 = 1000 -0 = 1111+5 = 0101 -6 = 1001+4 = 0100 -5 = 1010+3 = 0011 -4 = 1011+2 = 0010 -3 = 1100+1 = 0001 -2 = 1101

  • 8/13/2019 AComputer Arithmatic

    14/45

    Twos Compliment

    +3 = 00000011 +4 = 0100 -7 = 1001+2 = 00000010 +5 = 0101 -8 = 1000

    +1 = 00000001 +6 = 0110+0 = 00000000 +7 = 0111 -1 = 11111111 -4 = 1100

    -2 = 11111110 -5 = 1011 -3 = 11111101 -6 = 1010

  • 8/13/2019 AComputer Arithmatic

    15/45

    Benefits

    One representation of zero Arithmetic works easily (see later)

    Negating is fairly easy3 = 00000011Boolean complement gives 11111100

    Add 1 to LSB 11111101

  • 8/13/2019 AComputer Arithmatic

    16/45

    Geometric Depiction of TwosComplement Integers

  • 8/13/2019 AComputer Arithmatic

    17/45

  • 8/13/2019 AComputer Arithmatic

    18/45

    Negation Special Case 2

    -128 = 10000000bitwise not 01111111

    Add 1 to LSB +1Result 10000000So:

    -(-128) = -128 XMonitor MSB (sign bit)It should change during negation

  • 8/13/2019 AComputer Arithmatic

    19/45

    Range of Numbers

    8 bit 2s compliment+127 = 01111111 = 2 7 -1 -128 = 10000000 = -2 7

    16 bit 2s compliment+32767 = 011111111 11111111 = 2 15 - 1 -32768 = 100000000 00000000 = -2 15

  • 8/13/2019 AComputer Arithmatic

    20/45

    Conversion Between Lengths

    Positive number pack with leading zeros+18 = 00010010

    +18 = 00000000 00010010Negative numbers pack with leading ones-18 = 10010010

    -18 = 11111111 10010010i.e. pack with MSB (sign bit)

  • 8/13/2019 AComputer Arithmatic

    21/45

    Addition and Subtraction

    Normal binary additionMonitor sign bit for overflow

    Take twos compliment of substahend and addto minuend

    i.e. a - b = a + (-b)

    So we only need addition and complementcircuits

  • 8/13/2019 AComputer Arithmatic

    22/45

  • 8/13/2019 AComputer Arithmatic

    23/45

    Multiplication

    ComplexWork out partial product for each digit

    Take care with place value (column) Add partial products

  • 8/13/2019 AComputer Arithmatic

    24/45

    Multiplication Example

    1011 Multiplicand (11 dec) x 1101 Multiplier (13 dec)

    1011 Partial products 0000 Note: if multiplier bit is 1 copy 1011 multiplicand (place value)

    1011 otherwise zero 10001111 Product (143 dec) Note: need double length result

  • 8/13/2019 AComputer Arithmatic

    25/45

    Unsigned Binary Multiplication

  • 8/13/2019 AComputer Arithmatic

    26/45

    Execution of Example

  • 8/13/2019 AComputer Arithmatic

    27/45

    Flowchart for Unsigned BinaryMultiplication

  • 8/13/2019 AComputer Arithmatic

    28/45

    Multiplying Negative Numbers

    This does not work!Solution 1

    Convert to positive if requiredMultiply as aboveIf signs were different, negate answer

    Solution 2Booths algorithm

  • 8/13/2019 AComputer Arithmatic

    29/45

    Booths Algorithm

  • 8/13/2019 AComputer Arithmatic

    30/45

    Example of Booths Algorithm

  • 8/13/2019 AComputer Arithmatic

    31/45

  • 8/13/2019 AComputer Arithmatic

    32/45

  • 8/13/2019 AComputer Arithmatic

    33/45

    Real Numbers

    Numbers with fractionsCould be done in pure binary

    1001.1010 = 24

    + 20

    +2-1

    + 2-3

    =9.625Where is the binary point?Fixed?

    Very limited

    Moving?How do you show where it is?

  • 8/13/2019 AComputer Arithmatic

    34/45

    Floating Point

    +/- .significand x 2 exponent MisnomerPoint is actually fixed between sign bit and body

    of mantissaExponent indicates place value (point position)

    S i g

    n b i t

    BiasedExponent

    Significand or Mantissa

  • 8/13/2019 AComputer Arithmatic

    35/45

    Floating Point Examples

  • 8/13/2019 AComputer Arithmatic

    36/45

    Signs for Floating Point

    Mantissa is stored in 2s complimentExponent is in excess or biased notation

    e.g. Excess (bias) 128 means8 bit exponent fieldPure value range 0-255Subtract 128 to get correct value

    Range -128 to +127

  • 8/13/2019 AComputer Arithmatic

    37/45

    Normalization

    FP numbers are usually normalizedi.e. exponent is adjusted so that leading bit

    (MSB) of mantissa is 1Since it is always 1 there is no need to store it(c.f. Scientific notation where numbers arenormalized to give a single digit before thedecimal pointe.g. 3.123 x 10 3)

  • 8/13/2019 AComputer Arithmatic

    38/45

    FP Ranges

    For a 32 bit number8 bit exponent+/- 2 256 1.5 x 10 77

    AccuracyThe effect of changing lsb of mantissa23 bit mantissa 2 -23 1.2 x 10 -7

    About 6 decimal places

  • 8/13/2019 AComputer Arithmatic

    39/45

    Expressible Numbers

  • 8/13/2019 AComputer Arithmatic

    40/45

    IEEE 754

    Standard for floating point storage32 and 64 bit standards

    8 and 11 bit exponent respectivelyExtended formats (both mantissa and exponent)for intermediate results

  • 8/13/2019 AComputer Arithmatic

    41/45

    FP Arithmetic +/-

    Check for zeros Align significands (adjusting exponents)

    Add or subtract significandsNormalize result

  • 8/13/2019 AComputer Arithmatic

    42/45

    FP Arithmetic x/

    Check for zero Add/subtract exponents

    Multiply/divide significands (watch sign)NormalizeRound

    All intermediate results should be in doublelength storage

    Floating

  • 8/13/2019 AComputer Arithmatic

    43/45

    FloatingPointMultiplication

    Floating

  • 8/13/2019 AComputer Arithmatic

    44/45

    FloatingPointDivision

  • 8/13/2019 AComputer Arithmatic

    45/45

    Required Reading

    IEEE 754 on IEEE Web site