ec 413 computer organization - secure computing · department of electrical & computer engineering...

18
1 Department of Electrical & Computer Engineering EC 413 Computer Organization Prof. Michel A. Kinsy Lecture 2: Information Representation Department of Electrical & Computer Engineering Computing Systems § A system is a set of related components that works as a whole to achieve a goal § A system contains: Inputs Behavior Outputs § Behavior is a function that translates inputs to outputs Behavior inputs outputs : : Department of Electrical & Computer Engineering System Components § Components are electronic blocks: analog, digital, and mixed signal Analog system has values from a continuous set

Upload: others

Post on 20-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

  • 1

    Department of Electrical & Computer Engineering

    EC 413 Computer Organization

    Prof. Michel A. Kinsy

    Lecture 2: Information Representation

    Department of Electrical & Computer Engineering

    Computing Systems §  A system is a set of related components that

    works as a whole to achieve a goal §  A system contains:

    •  Inputs •  Behavior •  Outputs

    §  Behavior is a function that translates inputs to outputs

    Behaviorinputs outputs: :

    Department of Electrical & Computer Engineering

    System Components §  Components are electronic blocks: analog,

    digital, and mixed signal •  Analog system has values from a continuous set

  • 2

    Department of Electrical & Computer Engineering

    System Components §  Components are electronic blocks: analog,

    digital, and mixed signal •  Digital system is a system in which signals have a

    finite number of discrete values

    Department of Electrical & Computer Engineering

    Modern Computing Systems §  Modern computing systems are mainly digital

    systems §  Digital representation means that everything is

    represented by numbers only §  Digital representation is very suited for both

    numerical and non-numerical information or data processing •  Numerical values: 0, 4, 5567, 24354543, -2 •  Non-numerical values: There will be light! (Each

    letter in this sentence)

    Department of Electrical & Computer Engineering

    Modern Computing Systems §  Our physical world is analog and computing is

    interacting with the physical world: •  So we need to convert physical signals to digital

    then back to analog to communicate with the real world

    -

  • 3

    Department of Electrical & Computer Engineering

    Bit & Byte §  A bit is the smallest unit of information

    •  It represents one 2-way decision or a 2-way choice •  yes / no, true / false, on / off ... •  Abstraction of all of these is represented as 0 or 1

    §  A single digit with one of two values §  Binary digit à bit

    §  All information in a computer is stored and processed as bits •  High voltage/low voltage, current flowing/not

    flowing §  A byte is 8 bits that are treated as a unit

    Department of Electrical & Computer Engineering

    Review of of decimal numbers §  "Decimal" numbers have 10 digits

    •  0 1 2 3 4 5 6 7 8 9 §  One decimal digit represents one choice out of 10 §  2 decimal digits represents one choice out of 100

    •  00 01 02 … 10 11 12 … 20 21 22 … 98 99 §  Decimal numbers are short-hands for sums of

    powers of 10 §  1492 = 1 x 1000 + 4 x 100 + 9 x 10 + 2 x 1 §  = 1 x 103 + 4 x 102 + 9 x 101 + 2 x 100

    Department of Electrical & Computer Engineering

    Review of of decimal numbers §  Most us count in "base 10", using powers of 10 §  Number of items and number of digits are

    tightly related: •  One dictates the other •  Maximum number value given number of digit is

    §  basenumber of digits

    §  For example BU ID number has 9 digits §  How many possible student numbers can we

    form?

  • 4

    Department of Electrical & Computer Engineering

    Binary Number System §  It uses bits to represent numbers §  It follows the same rules as the decimal number

    system except has only two digits: 0 and 1 §  Number representation are based on powers of 2

    •  1, 2, 4, 8, 16, 32, … §  Instead of powers of 10 seen in the decimal system

    •  1, 10, 100, 1000, … §  1 binary digit can represent one choice from 2,

    count 2 things or specify 2 distinct values

    Department of Electrical & Computer Engineering

    Binary Number System §  1 binary digit (1-bit value)

    •  0 and 1 §  2 binary digits can represent one choice from 4,

    count 4 things or specify 4 distinct values •  00, 01, 10, 11

    §  3 binary digits can represent one choice from 8, count 8 things or specify 8 distinct values •  000, 001, 010, 011, 100, 101, 110 , 111

    Department of Electrical & Computer Engineering

    Binary Number System §  Binary numbers are short-hands for sums of

    powers of 2 •  11011 = 1 x 16 + 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20

    §  Most of us count in "base 10", using powers of 10

    §  Computer counts in "base 2", using power of 2

  • 5

    Department of Electrical & Computer Engineering

    Binary Number System §  8 bits (1 byte) can encode 28 = 256 different

    values §  e.g., numbers 0 .. 255 §  2 bytes (16 bits) can encode 216 = 65536

    values §  With 4 bytes (32 bits) can encode 232 =

    4,294,967,296 values §  With 8 bytes (64 bits) can encode 264 =

    18,446,744,073,709,551,616

    Department of Electrical & Computer Engineering

    Binary arithmetic §  It works just like decimal arithmetic

    Addition

    0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10

    Subtraction 0 - 0 = 0 0 - 1 = -1 1 - 0 = 1 1 - 1 = 0

    Small Problem We will see how to solve it later in the lecture

    Department of Electrical & Computer Engineering

    Converting binary to decimal §  Converting to decimal, so we can use

    polynomial evaluation •  101101012 =1x27 + 0x26 + 1x25 + 1x24 + 0x23 + 1x22 + 0x21 + 1x20 =128 + 32 + 16 + 4 + 1 = 18110

  • 6

    Department of Electrical & Computer Engineering

    Converting decimal to binary §  Divide by target base (2 in this case) §  Remainders become digits in the new

    representation §  Digits produced in right to left order §  Quotient is used as next dividend §  Stop when the quotient becomes zero, but use

    the corresponding remainder

    Department of Electrical & Computer Engineering

    Converting decimal to binary  97 ÷ 2 à quotient = 48, remainder = 1 (LSB) 48 ÷ 2 à quotient = 24, remainder = 0 24 ÷ 2 à quotient = 12, remainder = 0 12 ÷ 2 à quotient = 6, remainder = 0 6 ÷ 2 à quotient = 3, remainder = 0 3 ÷ 2 à quotient = 1, remainder = 1 1 ÷ 2 à quotient = 0 (Stop) remainder = 1 (MSB)

    Answer=11000012

    Department of Electrical & Computer Engineering

    Hexadecimal notation §  Binary number can be long and hard to read, so

    hexadecimal numbers were introduced §  It combines 4 bits into a single digit, written in

    base 16 §  A more compact and more readable

    representation of the same information §  Hexadecimal number system uses the symbols

    A, B, C, D, E, F for the digits 10, 11, 12, 13, 14, and 15, respectively

  • 7

    Department of Electrical & Computer Engineering

    Numbers and Bases Decimal Base-10 Binary Base-2 Hexadecimal Base-16

    0 00000 01 00001 12 00010 23 00011 34 00100 45 00101 56 00110 67 00111 78 01000 89 01001 910 01010 A11 01011 B12 01100 C13 01101 D14 01110 E15 01111 F16 10000 1017 10001 11

    Department of Electrical & Computer Engineering

    Text Representation §  ASCII: American

    Standard Code for Information Interchange •  It is an arbitrary

    but agreed-upon representation in the US

    •  It is now widely used around the world

    Department of Electrical & Computer Engineering

    Information Representation §  Unsigned and signed Integer, floating point

  • 8

    Department of Electrical & Computer Engineering

    Unsigned Integer §  An unsigned integer containing n bits can have

    a value between 0 and 2n - 1 §  Memory addresses are always represented by

    unsigned integers §  Given the binary number 11001:

    •  = 1 x 24 + 1 x 23 + 0 x 22 + 0 x 21 + 1 x 20 •  = 16 + 8 + 0 + 0 + 1 •  = 25

    Department of Electrical & Computer Engineering

    Signed Integer Representation §  Positive value representation alone are not the

    problem §  Negative value representation is the challenge

    •  To represent negative values, computer systems allocate the high-order bit to indicate the sign of a value

    •  The high-order bit is the leftmost bit in a binary number

    •  It is also called the most significant bit •  The remaining bits contain the value of the number

    Department of Electrical & Computer Engineering

    Signed Integer Representation §  There are three ways in which signed binary

    numbers may be expressed: •  Signed magnitude •  One’s complement •  Two’s complement

    §  In an 8-bit binary number, signed magnitude representation places the absolute value of the number in the 7 bits to the right of the sign bit

    •  4 = 0 0000100 •  -4 = 1 0000100

  • 9

    Department of Electrical & Computer Engineering

    Signed magnitude Representation §  Arithmetic operations on signed magnitude

    numbers are performed inside the computer in much the same way as humans carry out pencil and paper arithmetic

    §  Sum of 74 and 46 •  1- Convert 74 and 46 to binary •  2- Arrange as a sum but separate the sign bits from

    the magnitude bits 0 1 0 0 1 0 1 0 0 + 0 1 0 1 1 1 0 = 0 1 1 1 1 0 0 0

    Department of Electrical & Computer Engineering

    Signed magnitude Representation §  In this example, two values were picked such as

    the sum would fit into seven bits §  If that is not the case, there is a problem §  Sum of 102 and 46

    •  The carry from the seventh bit overflows and it is discarded

    •  Erroneous result: 102 + 46 = 36 0 1 1 0 0 1 1 0 0 + 0 1 0 1 1 1 0 = 0 0 1 0 0 1 0 0

    Department of Electrical & Computer Engineering

    Signed magnitude Representation §  Signed magnitude representation is easy for

    people to understand •  But it requires complicated computer hardware •  Another disadvantage of signed magnitude is that

    it allows two different representations for zero: positive zero and negative zero

    §  So computers systems uses complement systems for numeric value representation

  • 10

    Department of Electrical & Computer Engineering

    One’s complement §  With one’s complement

    addition, the carry bit is carried around and added to the sum

    §  Sum of 48 and – 19 •  19 in binary is 00010011 •  -19 in one’s complement is

    11101100 •  Answer is 29

    0 0 1 1 0 0 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 1

    + = +

    Department of Electrical & Computer Engineering

    One’s complement §  It amounts to little more than flipping the bits of a

    binary number §  In an 8-bit binary number using One’s

    complement •  4 = 0 0000100 •  -4 = 1 1111011

    §  In one’s complement, as with signed magnitude, negative values are indicated by a 1 in the high order bit

    •  Complement systems are useful because they eliminate the need for subtraction

    Department of Electrical & Computer Engineering

    One’s complement §  Although the end carry around adds some

    complexity, one’s complement is simpler to implement in hardware than signed magnitude.

    §  But it still has the disadvantage of having two different representations for zero: positive zero and negative zero

    §  Two’s complement solves this problem

  • 11

    Department of Electrical & Computer Engineering

    Two’s complement §  To express a value in two’s complement: §  If the number is positive, convert it to binary and

    it is done §  If the number is negative, find the one’s

    complement of the number and then add 1 •  4 = 0 0000100 •  -4 = 1 1111100

    Department of Electrical & Computer Engineering

    Two’s complement §  With Two’s complement

    arithmetic §  Just add the two binary numbers §  Discard any carries emitting from

    the high order bit §  Sum of 48 and – 19

    •  19 in binary is 00010011 •  -19 in one’s complement is

    11101100 •  -19 in two’s complement is

    11101101 •  Answer is 29

    0 0 1 1 0 0 0 0 1 1 1 0 1 1 0 1 = 0 0 0 1 1 1 0 1

    Department of Electrical & Computer Engineering

    Overflow §  In a computing system, resources are finite §  There is always the risk that the result of a

    calculation becomes too large to be stored in the computer

    §  Overflow can not always be prevented §  It can always be detected §  In complement arithmetic, an overflow condition

    is easy to detect.

  • 12

    Department of Electrical & Computer Engineering

    Overflow §  Using two’s complement binary arithmetic, the

    sum of 104 and 46 is

    §  The nonzero carry from the seventh bit overflows into the sign bit, resulting in an erroneous value: 104 + 46 = -106

    0 1 1 0 1 0 0 0 0 0 1 0 1 1 1 0 = 1 0 0 1 0 1 1 0

    Department of Electrical & Computer Engineering

    Overflow §  Good programmers stay alert for it §  Rule for detecting signed two’s complement

    overflow •  Carry in and carry out of the sign bit are different

    §  Rule for detecting unsigned number overflow •  There is carry out of the leftmost bit •  1111 + 1 = 0000

    Department of Electrical & Computer Engineering

    Representation Range §  3 bits

    •  Signed: -3 , 3 •  1’s: -3 , 3 •  2’s: -4 , 3

    §  6 bits •  Signed: -31, 31 •  1’s: -31, 31 •  2’s: -32, 31

    §  5 bits: •  Signed: -15, 15 •  1’s: -15, 15 •  2’s: -16, 15

    §  8 bits •  Signed: -127, 127 •  1’s: -127, 127 •  2’s: -128, 127

    §  Formula for calculating the range •  Signed & 1’s: -(2n-1 – 1) , (2n-1 – 1) •  2’s: -2n-1 , (2n-1 – 1)

  • 13

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Signed magnitude, one’s complement, and

    two’s complement representations alone are not useful in scientific or business applications

    §  Real number values over a wide range §  Numerals to the right of a base point represent

    negative powers of the base

    0.112 = 1 x 2-1 + 1 x 2-2 = 0.5 + 0.25

    = 0.75

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Converting 0.8125 to binary §  This method also works with any base. Just use

    the target base as the multiplier •  0.8125 * 2 = 1.6250 •  0.6250 * 2 = 1.2500 •  0.2500 * 2 = 0. 5000 •  0.5000 * 2 = 1. 0000

    §  Conversion is done when the product is zero or the desired number of binary places is reached

    Reading from top to bottom is: 0.812510 = 0.11012

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Computer systems use a form of scientific notation

    for floating-point representation §  Numbers written in scientific notation have three

    components: •  Sign Mantissa Exponent

    + 1.5 x 10-1

    §  Computer representation of a floating-point number consists of three fixed-size fields:

    Sign Exponent Significand

  • 14

    Department of Electrical & Computer Engineering

    Floating-Point Representation

    §  The one-bit sign field is the sign of the stored

    value §  The size of the exponent field, determines the

    range of values that can be represented §  The size of the significand determines the

    precision of the representation

    Sign Exponent Significand

    Department of Electrical & Computer Engineering

    Floating-Point Representation

    §  The IEEE-754 single precision floating point

    standard uses an 8-bit exponent and a 23-bit significand

    §  The IEEE-754 double precision standard uses an 11-bit exponent and a 52-bit significand

    Sign Exponent Significand

    Department of Electrical & Computer Engineering

    Floating-Point Representation

    §  The significand of a floating-point number is always preceded by an implied binary point

    §  The significand always contains a fractional binary value

    §  The exponent indicates the power of 2 to which the significand is raised

    Sign Exponent Significand

  • 15

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Express 3210 in the simplified 14-bit floating-

    point representation §  32 = 25 = 1.0 x 25 = + 0.1 x 26 §  Exponent field = 1102 = 610 §  Significand field 1

    §  How do we express fractional numbers 0.5 =2-1?

    + 00110 10000000

    Department of Electrical & Computer Engineering

    General Form §  Representation

    •  Bits to right of “binary point” represent fractional powers of 2 Represents rational number:

    bi bi–1 b2 b1 b0 b–1 b–2 b–3 b–j• • •• • • .124

    2i–12i

    • • •

    • • •

    1/21/41/8

    2–j

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  To provide for negative exponents, a biased

    exponent is used §  The IEEE-754 single precision floating point

    standard uses bias of 127 over its 8-bit exponent

    •  An exponent of 255 indicates •  Infinity if significand is zero •  NaN, “not a number,” often used to flag an error

    condition if the significand is nonzero §  The double precision standard has a bias of

    1023 over its 11-bit exponent

  • 16

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Sum of 1210 and 1.2510 using the 14-bit floating-

    point representation •  1210 = 0.1100 x 24 •  1.2510 = 0.101 x 21 = 0.000101 x 24 •  Thus, the sum is 0.110101 x 24

    Department of Electrical & Computer Engineering

    Floating-Point Representation §  Using the same number of bits, unsigned integers

    can express twice as many values as signed numbers

    §  Using two’s complement allows for one type of hardware/process to add both signed and unsigned numbers

    §  IEEE-754 floating point standards allow two representations for zero

    •  Programmers should avoid testing a floating-point value for equality to zero

    •  Negative zero does not equal positive zero

    Department of Electrical & Computer Engineering

    IEEE-754 Single Precision §  Single precision (32-bit) format

    §  Normalized rule: number represented is (-1)S×1.F×2E-127

    •  An exponent of 255 indicates §  Infinity if significand is zero §  NaN, “not a number,” often used to flag an error condition if

    the significand is nonzero

    §  Example: +101100.111è+1.01100111×25

    S E F

    1 8 23

    0 10000100 01100111000000000000000

  • 17

    Department of Electrical & Computer Engineering

    IEEE-754 Single Precision all zeros

    all ones

    S E M Represents 0 all zeros all zeros 0 1 all zeros all zeros -0 0 all ones all zeros 1 all ones all zeros

    0 or 1 all ones non-zero NaN

    ∞∞−

    E = 0

    E = 255

    Department of Electrical & Computer Engineering

    IEEE-754 Single Precision §  Examples

    •  0.0 §  0 00000000 00000000000000000000000

    •  1.0 (1.0 x 20) §  0 01111111 00000000000000000000000

    •  0.5 (0.1 binary = 1.0 x 2-1) §  0 01111110 00000000000000000000000

    •  0.75 (0.11 binary = 1.1 x 2-1) §  0 01111110 10000000000000000000000

    •  3.0 (11 binary = 1.1*21) §  0 10000000 10000000000000000000000

    •  -0.375 (-0.011 binary = -1.1*2-2) §  1 01111101 10000000000000000000000

    •  1 10000011 01000000000000000000000 = - 1.01 * 24 = -20.0

    Department of Electrical & Computer Engineering

    Other Representation ( ) ( ) ( )

    ( ) ( )22

    52210

    1011011.121011011.111.11011075.54

    ×≅

    ×==

    0 0 1 0 1 1 1 0 1

    Sign of the number

    mantissa Sign of the exponent

    exponent

    ( ) ( )( ) ( )201102

    5210

    21100.1

    21100.102832.0−

    ×=

    ×≅

    10 bit word (sign, sign of exponent, 4 for exponent, 4 for mantissa)

    0 1 0 1 1 0 1 1 0 0

    Sign of the number

    mantissa Sign of the exponent

    exponent

  • 18

    Department of Electrical & Computer Engineering

    Floating Point Operation •  Now consider adding 0.5 and -0.4375

    1.  Conversions §  0.5 = 0.12 = 1.0002 × 2–1 §  - 0.4375 = - 0.011102 = - 1.1102 × 2–2

    2.  New Representation §  0.5 + –0.4375 => 1.0002 × 2–1 + –1.1102 × 2–2

    3.  Align binary points §  Shift number with smaller exponent §  1.0002 × 2–1 + –0.1112 × 2–1

    4.  Add significands §  1.0002 × 2–1 + –0.1112 × 2–1 = 0.0012 × 2–1

    5.  Normalize result & check for over/underflow §  1.0002 × 2–4, with no over/underflow

    6.  Round and renormalize if necessary §  1.0002 × 2–4 (no change) = 0.0625

    Department of Electrical & Computer Engineering

    Floating Point Hardware Unit

    Small ALU

    Exponentdifference

    Control

    ExponentSign Fraction

    Big ALU

    ExponentSign Fraction

    0 1 0 1 0 1

    Shift right

    0 1 0 1

    Increment ordecrement

    Shift left or right

    Rounding hardware

    ExponentSign Fraction

    S t i l l n o r m a l i z e d ?

    4 . R o u n d t h e s i g n i f i c a n d t o t h e a p p r o p r i a t en u m b e r o f b i t s

    Y e sO v e r f l o w o ru n d e r f l o w ?

    S t a r t

    N o

    Y e s

    D o n e

    1 . C o m p a r e t h e e x p o n e n t s o f t h e t w o n u m b e r s .S h i f t t h e s m a l l e r n u m b e r t o t h e r i g h t u n t i l i t se x p o n e n t w o u l d m a t c h t h e l a r g e r e x p o n e n t

    2 . A d d t h e s i g n i f i c a n d s

    3 . N o r m a l i z e t h e s u m , e i t h e r s h i f t i n g r i g h t a n di n c r e m e n t i n g t h e e x p o n e n t o r s h i f t i n g l e f t

    a n d d e c r e m e n t i n g t h e e x p o n e n t

    N o E x c e p t i o n

    Department of Electrical & Computer Engineering

    Next Class §  Introduction to programming with C