Salta al contenuto
Note per Studenti Arithmetic Logic Unit Report

Arithmetic Logic Unit

In questa pagina 6
In questa pagina 5

The ALU is the part of the processor that produces new information; everything else moves or stores data. It receives two operands (from registers or from the instruction), an operation code from the control unit (Hardwired and Microprogrammed ControlWhat the control unit does, control signals of a single-cycle datapath with the table for each instruction class, hardwired control (combinational or finite-state machine), microprogrammed control (control memory, horizontal and vertical microinstructions, microsequencer), and a comparison.Hardwired and Microprogrammed Control →), and produces the result and the flags N, Z, C, V stored in the status register (CPU Structure and RegistersArchitecture versus organization, the stored-program (von Neumann) machine, the internal components of a CPU (ALU, control unit, register file, internal bus), user-visible and control/status registers, the status word with flags and supervisor bit, and how many registers are worth having.CPU Structure and Registers →). Typical structure: an adder (AddersHalf adder and full adder, generate-propagate-delete decomposition, the ripple-carry adder and its linear worst-case delay, the adder-subtractor, and the fast structures carry-lookahead, carry-bypass, carry-select and square-root carry-select with their delay formulas and optimal block sizes.Adders →), a logic unit (AND, OR, XOR, NOT bit by bit, in parallel) and a multiplexer choosing the output.

1-bit ALU

Definition (1-bit ALU). For bit ii: an AND gate, an OR gate, a full adder and a multiplexer that selects which result goes to the output.

  • inputs: aia_i, bib_i, carry cic_i, operation select;
  • outputs: result rir_i, carry ci+1c_{i+1}.

Example. With ai=1a_i=1, bi=1b_i=1, ci=0c_i=0 the full adder gives ri=0r_i=0, ci+1=1c_{i+1}=1; the multiplexer chooses whether AND, OR or the sum goes out.

N-bit ALU

Definition (N-bit ALU: subtraction, NOR, slt, zero, overflow). NN one-bit ALUs with carries in cascade (or with carry lookahead). Additions:

Typical signal encoding (MIPS style):

Ainvert Binvert Operation Function
0 0 AND a⋅ba\cdot b
0 0 OR a+ba+b
0 0 add arithmetic a+ba+b
0 1 add with c0=1c_0=1 a−ba-b
0 1 less slt
1 1 AND NOR

Example (flags after an 8-bit subtraction). a=0101 0000a=0101\,0000 (80), b=0111 0000b=0111\,0000 (112): a−b=a+b‾+1=0101 0000+1000 1111+1=1110 0000a-b=a+\overline b+1=0101\,0000+1000\,1111+1=1110\,0000.

  • signed result −32-32;
  • N = 1, Z = 0;
  • C = 0: no carry out, i.e. a borrow occurred: unsigned 80<11280<112;
  • V = 0: a subtraction of two numbers of the same sign cannot overflow (as a sum, 80+(−112)80+(-112) has operands of different sign).

This is exactly what CMP does in ARM before a conditional branch.

Flags

  • Z: all result bits are 0. N: MSB of the result.
  • C: carry out of the last stage (unsigned: overflow in addition, no borrow in subtraction).
  • V (signed overflow): operands of the same sign give a result of the opposite sign; equivalent to cN−1⊕cNc_{N-1}\oplus c_N. Example: 0110+0101=10110110+0101=1011 (4 bits) gives V=1V=1, N=1N=1, Z=0Z=0, C=0C=0.

The ALU critical path is the addition: speed depends on the adder used (AddersHalf adder and full adder, generate-propagate-delete decomposition, the ripple-carry adder and its linear worst-case delay, the adder-subtractor, and the fast structures carry-lookahead, carry-bypass, carry-select and square-root carry-select with their delay formulas and optimal block sizes.Adders →).

Comparators

Equality. A=BA=B iff every pair of bits is equal: ei=Ai⊕Bi‾e_i=\overline{A_i\oplus B_i} (XNOR), EQ=eN−1⋯e0EQ=e_{N-1}\cdots e_0 (AND tree, or NOR of the XORs).

Formula (magnitude comparator). Compare bits from the most significant: A>BA>B if at the first differing bit Ai=1A_i=1, Bi=0B_i=0. With gi=AiBi‾g_i=A_i\overline{B_i}: GT=gN−1+eN−1(gN−2+eN−2(gN−3+… )),EQ=∏ei.GT=g_{N-1}+e_{N-1}\big(g_{N-2}+e_{N-2}(g_{N-3}+\dots)\big),\qquad EQ=\prod e_i.

Example. A=1011A=1011, B=1001B=1001: e3=1e_3=1, e2=1e_2=1, g1=1g_1=1, so GT=0+1⋅(0+1⋅1)=1GT=0+1\cdot(0+1\cdot1)=1 (11>911>9).

Property (comparison by subtraction and flags). Compute A−B=A+B‾+1A-B=A+\overline B+1 and read: ZZ for equality; for unsigned numbers A≥BA\ge B if the carry out is 11 (no borrow); for signed numbers A<BA<B if N⊕V=1N\oplus V=1. This is how processors do it.

Example. A=0110A=0110, B=0011B=0011 unsigned: 0110+1100+1=1 00110110+1100+1=1\,0011, carry out 11, so A≥BA\ge B.

Sharing a bus

On a bus several sources (registers, memory, ALU) transmit at different times on the same line. If two static CMOS outputs drive the line with different values there is a direct path from VDDV_{DD} to ground through the two drivers: contention, an intermediate (invalid) voltage and high current. Outputs must be able to disconnect:

  • Tri-state: an enable signal; when disabled the output is floating (high impedance, ZZ, neither 0 nor 1). At most one source at a time may have en=1en=1 (guaranteed by the control unit through a decoder).
  • Open-drain: gates have only the pull-down network and can only force 00; a pull-up brings the bus to 11. The bus is the wired-AND of the outputs.

Other computation units

Common mistakes

  • Thinking that in ARM C = 1 after a subtraction means a borrow: it is the opposite, C = 1 means no borrow (a≥ba\ge b unsigned).
  • Computing Z from the most significant bit only.
  • Confusing C (unsigned) and V (signed).
  • Writing subtraction as A+B‾A+\overline B without +1+1.
  • Connecting two push-pull outputs to the same line without tri-state.

Versione ripasso

Produces results and flags N, Z, C, V from two operands and an opcode from the control unit (Hardwired and Microprogrammed ControlWhat the control unit does, control signals of a single-cycle datapath with the table for each instruction class, hardwired control (combinational or finite-state machine), microprogrammed control (control memory, horizontal and vertical microinstructions, microsequencer), and a comparison.Hardwired and Microprogrammed Control →); core: adder (AddersHalf adder and full adder, generate-propagate-delete decomposition, the ripple-carry adder and its linear worst-case delay, the adder-subtractor, and the fast structures carry-lookahead, carry-bypass, carry-select and square-root carry-select with their delay formulas and optimal block sizes.Adders →) + logic unit + output multiplexer.

Construction

Flags

N = MSB; Z = result 0; C = carry out (unsigned overflow in addition, no borrow in subtraction); V = signed overflow. Example: 0101 0000−0111 0000=0101 0000+1000 1111+1=1110 0000=−320101\,0000-0111\,0000=0101\,0000+1000\,1111+1=1110\,0000=-32: N=1, Z=0, C=0 (borrow, 80<11280<112), V=0. This is CMP in ARM.

Comparators

Equality: AND of XNORs. Magnitude from the MSB: GT=gN−1+eN−1(gN−2+eN−2(… ))GT=g_{N-1}+e_{N-1}(g_{N-2}+e_{N-2}(\dots)). By subtraction: ZZ equality; unsigned A≥BA\ge B iff carry out =1=1; signed A<BA<B iff N⊕V=1N\oplus V=1.

Bus

Two push-pull outputs with different values: contention (high current). Use tri-state (enable, high impedance ZZ, one active source at a time) or open-drain (only pull-down, pull-up to 1, wired-AND).

Other units

Multiplier, divider, barrel shifter (Shift Registers, Shifters and MultipliersShift registers (serial-parallel conversion, hold constraint), combinational shifters and the barrel shifter with log2 N multiplexer levels, and multipliers: partial products, array multiplier with N squared AND gates and N(N-1) full adders, Wallace tree, Booth, sequential shift-and-add, and dedicated FPGA DSP blocks.Shift Registers, Shifters and Multipliers →), FPU (Fixed-Point and Floating-Point NumbersFixed-point numbers as an integer divided by 2 to the F with resolution and a sensor example, floating point in base 2, the IEEE 754 single and double formats, conversions in both directions with worked examples, special values and denormals, range, precision, rounding and floating-point operations.Fixed-Point and Floating-Point Numbers →).

Common mistakes: ARM C = 1 means no borrow; Z is not the MSB alone; C is unsigned and V signed; A+B‾A+\overline B needs +1+1.

Teoria collegata