lecture 9 registers-1

Upload: uninj-xela

Post on 04-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Lecture 9 Registers-1

    1/20

    Registers 1

    Registers

    A register is another common sequential device:. Theyre a good example of sequential analysis and design.

    They are also frequently used in building larger sequential circuits. Registers hold larger quantities of data than individual flip-flops.

    Registers are central to the design of modern processors. Register is a group of flip-flops. Its basic function is to

    hold information within a digital system so as to make itavailable to the logic units during the computing process.

  • 7/31/2019 Lecture 9 Registers-1

    2/20

    Registers 2

    What good are registers?

    Flip-flops are limited because they can store only one bit.

    Most computers work with integers and single-precisionfloating-point numbers that are 32-bits long. A register is an extension of a flip-flop that can store

    multiple bits.

    Registers are commonly used as temporary storage in aprocessor. They are faster and more convenient than main

    memory.

    More registers can help speed up complex calculations.

  • 7/31/2019 Lecture 9 Registers-1

    3/20

    Registers 3

    A basic register

    We can store multiple bits by putting flip-flops together! A 4-bit register Reg-4, is on the right, and its internal

    implementation is below. This register uses D flip-flops, so its easy to store

    data without worrying about flip-flop input equations.

    All the flip-flops share a common CLK and CLR signal.

  • 7/31/2019 Lecture 9 Registers-1

    4/20

    Registers 4

    Adding a parallel load operation

    The input D3-D0 is copied to the output Q3-Q0 on everyclock cycle. How can we store the current value for more than one cycle?

    Lets add a load input signal LD to the register. If LD = 0, the register keeps its current contents. If LD = 1, the register stores a new value, taken from inputs D3-D0.

    LD Q(t+1)

    0 Q(t)

    1 D3-D0

  • 7/31/2019 Lecture 9 Registers-1

    5/20

    Registers 5

    Clock gating

    We could implement the load ability by playing games with the CLKinput, as shown below.

    When LD = 0, the flip-flop C inputs are held at 1. There is nopositive clock edge, so the flip-flops keep their current values.

    When LD = 1, the CLK input passes through the OR gate, so the flip-flops can receive a positive clock edge and can load a new value fromthe D3-D0 inputs.

  • 7/31/2019 Lecture 9 Registers-1

    6/20

    Registers 6

    Clock gating is bad

    This is called clock gating, since gates are added to the clock signal. There are timing problems similar to those of latches. Here, LD must be

    kept at 1 for the correct length of time (one clock cycle) and no longer. The clock is delayed a little bit by the OR gate.

    In more complex scenarios, different flip-flops in the system couldreceive the clock signal at slightly different times.

    This clock skew can lead to synchronization problems.

  • 7/31/2019 Lecture 9 Registers-1

    7/20

    Registers 7

    A better parallel load

    Another idea is to modify the flip-flop D inputs and not the clock signal. When LD = 0, the flip-flop inputs are Q3-Q0, so each flip-flop just

    keeps its current value. When LD = 1, the flip-flop inputs are D3-D0, and this new value is

    loaded into the register.

  • 7/31/2019 Lecture 9 Registers-1

    8/20

    Registers 8

    A shift registershifts its output once every clock cycle.

    SIis an input that supplies a new bit to shift intothe register. For example, if on some positive clock edge we have:

    SI = 1Q0-Q3 = 0110

    then the next state will be:

    Q0-Q3 = 1011

    The current Q3 (0 in this example) will be lost on the next cycle.

    Shift registers

    Q0(t+1) = SIQ1(t+1) = Q0(t)Q2(t+1) = Q1(t)Q3(t+1) = Q2(t)

  • 7/31/2019 Lecture 9 Registers-1

    9/20

    Registers 9

    Shift direction

    The circuit and example make it look like the register shifts right.

    But it really depends on your interpretation of the bits. If you considerQ3 to be the most significant bit instead, then the register is shifting

    in the oppositedirection!

    Q0(t+1) = SIQ

    1(t+1) = Q

    0(t)

    Q2(t+1) = Q1(t)Q3(t+1) = Q2(t)

    Present Q0-Q3 SI Next Q0-Q3

    ABCD X XABC

    Present Q3-Q0 SI Next Q3-Q0

    DCBA X CBAX

  • 7/31/2019 Lecture 9 Registers-1

    10/20

    Registers 10

    Shift registers with parallel load

    We can add a parallel load, just like we did for regular registers. When LD = 0, the flip-flop inputs will be SIQ0Q1Q2, so the register

    shifts on the next positive clock edge. When LD = 1, the flip-flop inputs are D0-D3, and a new value is

    loaded into the shift register, on the next positive clock edge.

  • 7/31/2019 Lecture 9 Registers-1

    11/20

    Registers 11

    Shift registers in LogicWorks

    Here is a block symbol for the Shift Reg-4 from LogicWorks. Theimplementation is shown on the previous page, except the LD input here

    is active-low instead.

  • 7/31/2019 Lecture 9 Registers-1

    12/20

    Registers 12

    Other types of shift registers

    Logical shifts Standard shifts like we just saw. In the absence of aSI input, 0 occupies the vacant position.

    Left: 0110 -> 1100 Right: 0110 -> 0011

    Circular shifts (also called ring counters or rotates) The shifted outbit wraps around to the vacant position.

    Left: 1001 -> 0011

    Right: 1001 -> 1100 Switch-tail ring counter (aka Johnson counter) Similar to the ring

    counter, but the serial input is the complement of the serial output.

    Left: 1001 -> 0010 Right: 1001 -> 0100

    Arithmetical shifts Left shifting is the same as a logical shift. Rightshifting however maintains the MSB. Left: 0110 -> 1100 Right: 0110 -> 0011; 1011 -> 1101

  • 7/31/2019 Lecture 9 Registers-1

    13/20

    Registers 13

    Serial data transfer

    One application of shift registers is converting between serial dataand parallel data.

    Computers typically work with multiple-bit quantities. ASCII text characters are 8 bits long. Integers, single-precision floating-point numbers, and screen pixels

    are up to 32 bits long.

    But sometimes its necessary to send or receive data serially, or one bit

    at a time. Some examples include: Input devices such as keyboards and mice. Output devices like printers. Any serial port, USB or Firewire device transfers data serially. Recent switch from Parallel ATA to Serial ATA in hard drives.

  • 7/31/2019 Lecture 9 Registers-1

    14/20

    Registers 14

    Receiving serial data

    To receiveserial data using a shift register: The serial device is connected to the registers SI input.

    The shift register outputs Q3-Q0 are connected to the computer. The serial device transmits one bit of data per clock cycle.

    These bits go into the SI input of the shift register. After four clock cycles, the shift register will hold a four-bit word.

    The computer then reads all four bits at once from the Q3-Q0 outputs.

    serial device

    computer

  • 7/31/2019 Lecture 9 Registers-1

    15/20

    Registers 15

    Sending data serially

    To senddata serially with a shift register, you do the opposite: The CPU is connected to the registers D inputs.

    The shift output (Q3 in this case) is connected to the serial device. The computer first stores a four-bit word in the register, in one cycle. The serial device can then read the shift output.

    One bit appears on Q3 on each clock cycle. After four cycles, the entire four-bit word will have been sent.

    serial device

    computer

  • 7/31/2019 Lecture 9 Registers-1

    16/20

    Registers 16

    Registers in Modern Hardware

    CPU GPR's Size L1 C ache L2 C ache

    Pentium 4 8 32 bits 8 KB 512 KB

    Athlon XP 8 32 bits 64 KB 512 KB

    Athlon 64 16 64 bits 64 KB 1024 KB

    PowerPC 970 (G5) 32 64 bits 64 KB 512 KB

    Itanium 2 128 64 bits 16 KB 256 KB

    MIPS R14000 32 64 bits 32 KB 16 MB

    Registers store data in the CPU Used to supply values to the ALU. Used to store the results.

    If we can use registers, why bother with RAM?

    Answer: Registers are expensive! Registers occupy the most expensive spaceon a chip the core.

    L1 and L2 cache are very fast RAM but notas fast as registers.

    Dunnington. Source INtel

  • 7/31/2019 Lecture 9 Registers-1

    17/20

    Registers 17

    Shift versus Multiply and Divide

    You can multiply by powers of two by shifting to the left Example:

    3 * 2 = 6; 3*22 = 12 0011 1 = 0100; 1000 >> 2 = 0010; 0100 >> 1 = 0010; 1100 >> 1= 1110

    -4 en twoscomplement

    -2 en twoscomplement

  • 7/31/2019 Lecture 9 Registers-1

    18/20

    Registers 18

    Why should I use shift instead of multiply?

    Program 1: Multiplication

    #include ..

    main() {scanf(%d,&mul);start = _rdtsc();for (i=0;i

  • 7/31/2019 Lecture 9 Registers-1

    19/20

    Registers 19

    Why should I user shift instead of integer division?

    Program 1: Division

    #include ..

    main() {scanf(%d,&mul);start = _rdtsc();for (i=0;i mul;}end = _rdtsc();printf("It took %llu cycles\n",end-start);return 0;

    }

    Output: It took 912 cycles

  • 7/31/2019 Lecture 9 Registers-1

    20/20

    Registers 20

    Registers summary

    A register is a special state machine that stores multiple bits ofdata.

    Several variations are possible: Parallel loading to store data into the register. Shifting the register contents either left or right. Counters are considered a type of register too!

    One application of shift registers is converting between serialand parallel data. Most programs need more storage space than registers provide.

    Well introduce RAM to address this problem. Registers are a central part of modern processors, as we will see

    in coming weeks.