Docsity

Computer Architecture: Understanding the Arithmetic and Logic Unit (ALU), Lecture notes of Microprocessors

Partial preview of the text

Download Computer Architecture: Understanding the Arithmetic and Logic Unit (ALU) and more Lecture notes Microprocessors in PDF only on Docsity!

CSE- 2823

Computer Architecture

Dr. Md. Waliur Rahman Miah

Associate Professor, CSE, DUET

Lecture- 1

ALU- 1

1

  • Fundamentals of the

computer:

  • Basic functional units and

elements of a computer,

  • Basic Operational concepts,
  • Bus structures,
  • Performance,
  • Historical perspective;
  • Instruction sets and

addressing modes:

  • Memory locations and

addresses,

  • Instructions and instruction

sequencing,

  • Types of instruction

operations,

  • Addressing modes,
  • Assembly language,
  • I/O operations,
  • Stacks and queues,
  • Subroutines;
  • Input /Output Organization:
  • Accessing I/O devices,
  • I/O modules,
  • Programmed I/O,
  • Interrupt-driven I/O,
  • Direct Memory Access,
  • I/O channels and processors; Syllabus – First Part

Today’s Topic Arithmetic and logical processing unit (ALU) Ref: Ch-9 Stallings Ch-3 Hennessy-Petterson

Figure from Reference [2] page-3. Basic functional units of a Computer

ALU Registers

  • When operands are brought into the processor, they are stored in high-speed storage elements called registers.
  • Each register can store one word of data.
  • Access times to registers are even shorter than access times to the cache unit on the processor chip.

ALU Inputs and Outputs

  • Sign Magnitude: One's Complement Two's Complement 000 = 0 000 = 0 000 = 0 001 = +1 001 = +1 001 = + 010 = +2 010 = +2 010 = + 011 = +3 011 = +3 011 = + 100 = 0 100 = - 3 100 = - 4 101 = - 1 101 = - 2 101 = - 3 110 = - 2 110 = - 1 110 = - 2 111 = - 3 111 = 0 111 = - 1
  • Issues:
    • balance – equal number of negatives and positives
    • ambiguous zero – whether more than one zero representation
    • ease of arithmetic operations
  • Which representation is best? Can we get both balance and non- ambiguous zero? Possible Representations ambiguous zero ambiguous zero

Sign-Magnitude

  • Left most bit is sign bit
    • 0 means positive
    • 1 means negative
  • +18 = 00010010
    • 18 = 10010010
  • Problems
    • Need to consider both sign and magnitude in arithmetic
    • Two representations of zero (+0 and - 0)
      • 0 = 00000000
      • 0 = 10000000

Benefits of 2’s Compliment

  • One representation of zero
  • Arithmetic works easily (see later)
  • Negating is fairly easy
    • 3 = 00000011
    • Boolean complement gives 11111100
    • Add 1 to LSB 11111101

Representation Formulae

  • Two’s complement: xn xn- 1 …x 0 = xn * - 2 n + xn- 1 * 2 n- 1 + … + x 0 * 2 0 or xnX’ = xn * - 2 n + X’ (writing rightmost n bits xn- 1 …x 0 as X’) = X’, if xn = 0
  • 2 n
  • X’, if xn = 1
  • One’s complement: xnX’ = X’, if xn = 0 - 2 n + 1 + X’, if xn = 1

Negation Special Case 2

    • 128 = 10000000
  • bitwise not 01111111
  • Add 1 to LSB +
  • Result 10000000
  • So:
    • (-128) = - 128 X
  • i.e. +128 cannot be represented by a 8 bit 2’s complement format
  • Monitor MSB (sign bit)
  • It should change during negation

Range of Numbers

  • 8 bit 2s compliment
    • 127 = 01111111 = 2
  • 1
  • 128 = 10000000 = - 2
  • 16 bit 2s compliment
    • 32767 = 011111111 11111111 = 2
  • 1
  • 32768 = 100000000 00000000 = - 2
  • 32 bit signed numbers: (^0000 0000 0000 0000 0000 0000 0000 0000) two = (^0) ten (^0000 0000 0000 0000 0000 0000 0000 0001) two = + (^1) ten (^0000 0000 0000 0000 0000 0000 0000 0010) two = + (^2) ten ... (^0111 1111 1111 1111 1111 1111 1111 1110) two = + 2,147,483,646ten (^0111 1111 1111 1111 1111 1111 1111 1111) two = + 2,147,483,647ten (^1000 0000 0000 0000 0000 0000 0000 0000) two = – 2,147,483,648ten (^1000 0000 0000 0000 0000 0000 0000 0001) two = – 2,147,483,647ten (^1000 0000 0000 0000 0000 0000 0000 0010) two = – 2,147,483,646ten ... (^1111 1111 1111 1111 1111 1111 1111 1101) two = – (^3) ten (^1111 1111 1111 1111 1111 1111 1111 1110) two = – (^2) ten (^1111 1111 1111 1111 1111 1111 1111 1111) two = – (^1) ten 2’s complement - 32 bits example minint maxint Negative integers are exactly those that have leftmost bit 1

Addition and Subtraction

  • Normal binary addition
  • Monitor sign bit for overflow
  • Take twos compliment of substrahend and add to minuend - i.e. a - b = a + (-b)
  • So we only need addition and complement circuits