






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







The objectives of this laboratory assignment are to
The pMIPS Arithmetic Logic Unit (ALU)
An arithmetic logic unit (ALU) is a digital system that performs arithmetic, logical, and shift operations on two numbers called operands. An ALU usually contains a set of control signals that choose which operation to perform among the supported operations. In addition to producing the result of the specific operation, an ALU usually produces certain flag bits required by a microprocessor. Typically, an ALU contains a zero flag (asserted when the result is zero), carry flag (asserted when an arithmetic result produces a carry), and an overflow flag (asserted when a signed arithmetic result overflows).
The pMIPS ALU is a 32-bit ALU supporting all of the required arithmetic and logical operations provided by the pMIPS ISA subset. The top-level interface specification of the 32-bit pMIPS ALU is given in Table 1.
Port Mode Type Size Description A, B (^) Input STD_LOGIC_VECTOR (^) 32 The first ALU operand
ALUOp (^) In STD_LOGIC_VECTOR (^) 4 The ALU operation control signal
Result (^) Out STD_LOGIC_VECTOR (^) 32 The ALU output as a function of the control signal
C (^) Out STD_LOGIC (^) 1 Asserted when arithmetic operations and the result produces a carry
Z (^) Out STD_LOGIC (^) 1 Asserted when the result is zero
V (^) Out STD_LOGIC (^) 1 Asserted when signed arithmetic operations and overflow occurs
Table 1: Interface Specification of the top-level 32-bit pMIPS ALU
The pMIPS ALU supports a total of thirteen operations categorized by four operation types. Table 2 describes the pMIPS ALU supported operation types, the corresponding operation code values, and description of the individual operations.
Figure 1: The 32-bit Boolean Logic Unit (BLU)
All four 32-bit Boolean logic operations are continuously computed, but the 32-bit, 4-to-1 multiplexer (controlled by ALUOp[1:0] ) chooses among the four logical operations to route to the output.
The Logarithmic Shift Unit (LSU)
The pMIPS ALU is required to perform three shift operations: shift left logical ( SLL ), shift right logical ( SRL ), and shift right arithmetic ( SRA ). These three shift operations operate on one data operand based on another input operand that indicates the shift amount. As indicated in Table 2, the shift operation type is indicated by setting ALUOp[3:2] = 112. Table 4 below shows the values of ALUOp[1:0] that correspond to the three shift operations. Note, ALUOp[1:0] = 012 is not used, thus a pre-condition exists to operate the ALU. The precondition states that ALUOp = 11012 should never be applied as a control signal since it does not correspond to any valid ALU operation.
Operation Type
ALU Operation Code Description ALUOp[3] ALUOp[2] ALUOp[1] ALUOp[0]
Shift
1 1 (^0 0) Bitwise Shift Left Logical ( SLL ) 1 1 (^0 1) NOT USED 1 1 (^1 0) Bitwise Shift Right Logical ( SRL ) 1 1 (^1 1) Bitwise Shift Right Arithmetic ( SRA )
Table 4: Decomposing the Shift Type Operation Codes
To implement the specifications described in Table 4, a combinational shifter circuit is required. A combinational shift circuit is a logic circuit which shifts an n-bit operand by a specific amount without the use of a clock or any state (sequential) elements. Irrespective of the circuit organization, all shift circuits have two attributes associated with shifting, the shift type and the shift direction. The shift type can be either logical or arithmetic. Logical shifting is distinguished from arithmetic shifting based on the kind of bits that replace the shifted bits. Logical shifting replaces the shifted bits with zeros while arithmetic shifting replaces the shifted bits with the MSB of the binary number being shifted. Logical shifting does not preserve the sign of the operand while arithmetic shifting does, since it performs somewhat of a sign-extension operation. Shift direction is self explanatory; bits can be shifted from either the left or the right side of the binary number.
To implement the combinational shifter, logarithmic shifter architecture will be used to implement the shifters required for the LSU. Logarithmic n-bit shifters utilize log 2 (n), 2-to-1 n-bit multiplexers to perform various shift operations. Each multiplexer stage is controlled by a bit position of the shift amount input signal. The advantage of the logarithmic approach is that it is easy to implement, however, the disadvantage is that there are log 2 (n) n-bit, 2-to- 1 multiplexer delays for input signals to propagate to the output.
Three combinational logic circuits that perform 32-bit left shift logical (LSL), right shift logical (RSL), and right shift arithmetic (RSA) operations of a 32-bit operand ( X[31:0] ) using a 5-bit shift amount ( shamt[4:0] ) are shown in Figure 2. Study the circuits in Figure 2 to understand how each circuit performs the required shift operations.
Figure 2: Three, 32-bit Combinational Shift Circuits: LSL, RSL, and RSA
Generally, each multiplexer level chooses from an appropriate shift amount. For example, the first level (the level with shamt[4] as the select input) chooses between a non-shifted input X , or X shifted left (logically) or right (logically or arithmetically) by sixteen (2^4 ) units. If shamt[4] is logic high, the input operand, X , must be shifted by at least sixteen bits. This pattern is used for each bit position. The only difference among all three circuits is how the operands are manipulated in each stage based on the shift direction and shift type.
Having circuits that perform the three required shift operation types, the three shift circuits must be combined using additional logic to formulate the complete 32-bit logarithmic shift unit (LSU). The LSU datapath is constructed hierarchically by combining each shift sub-circuit as indicated in Figure 3. Additional multiplexers are used for choosing shift-direction ( ALUOp[1] ) and right-shift type ( ALUOp[0] ) according specifications outlined in Table 4.
Figure 3: The 32-bit Logarithmic Shift Unit (LSU)
relatively trivial matter of determining whether the result is less than zero. Instead of a large comparator, which will consume a number of gates, the 32-bit ASU can be reused with a minimal amount of additional logic to determine whether the result is less than zero. Before a discussion of how to make this determination, Table 7 is provided below to review the operation codes for the Comparison operation type of the 32-bit pMIPS ALU.
Operation Type ALU Operation Code Description ALUOp[3] ALUOp[2] ALUOp[1] ALUOp[0]
Comparison
(^1 0) (^1 0) Unsigned Set On Less Than ( SLTU ) 1 0 (^1 1) Signed Set on Less Than ( SLT )
Table 7: Decomposing the Comparison Type Operation Codes
A discussion of Table 7 follows. To facilitate the comparison operation, the 32-bit ASU must perform subtraction. This occurs when ALUOp[1:0] = 10 or ALUOp[1:0] = 11. Set-on-less-than ( SLT ) requires a signed subtraction, thus it is encoded as ALUOp[1:0] = 10. Set-on-less-than-unsigned ( SLTU ) requires unsigned subtraction, thus it is encoded as ALUOp[1:0] = 11. The remaining two encodings for this sub-block will be undefined. To generate the proper conditions, the CLU requires the following signals: Cout from the 32-bit ASU, the sing bit ( SumSign ) from the 32-bit ASU result, the sign bits ( ASign and BSign ) from the two operands of the 32-bit ASU, and the lower-order two-bits ( ALUOp[1:0] ) from the ALU operation code. Since we are only concerned with a small number of input bits to determine the output of the 32-bit CLU, the CLU will be specified using a truth table.
First, focus attention on the set-on-less-than ( SLT ) operation. There are four possible combinations of the signs of the two input operands: both positive; both are negative; A is positive and B is negative; A is negative and B is positive. When the signs of the inputs are different, determining the output of the 32-bit CLU is trivial. If operand A is negative and operand B is positive, then operand A must be less than operand B. Conversely, if operand A is positive and operand B is negative then operand A can never be less than operand B. When the input operands have the same sign the sign of the operands is not enough; the result of the signed subtraction must also be taken into account. Two inputs with the same sign can never cause an overflow in subtraction, so an incorrect set-on-less-than answer cannot result. If the input operands are the same sign, then whenever A is smaller than B the result of subtracting operand B from operand A must result in a negative number. Therefore, when performing the subtraction, if the sign -bit of the result ( SumSign ) is a logic high (negative), operand A is less than operand B ( A < B ). Otherwise, if the sign-bit of the result ( SumSign ) is a logic low (positive), then operand A is greater than operand B ( A > B ).
Next, focus attention on the set-on-less-than-unsigned ( SLTU ) operation. This case has a simple test. In unsigned representation, operands A and B are both positive numbers. Subtracting two positive numbers will result in a positive number if operand A is greater than operand B ( A > B ). Otherwise, subtracting two positive numbers will result in a negative number if operand A is less than operand B ( A < B ). However, a negative number cannot be represented using an unsigned representation since this yields an overflow condition. Overflow for unsigned subtraction suggests that the result is a negative number (it is impossible to subtract two unsigned numbers and get a result too large to represent). The unsigned overflow condition can be tested by inspecting carry-out ( Cout ) of the result’s (from the 32-bit ASU) MSB ( SumSign ). For unsigned addition, an asserted Cout signal indicates overflow. In unsigned subtraction, however, the overflow condition is reversed: an asserted Cout signal indicates the common case; a de-asserted Cout signal indicates overflow. Since unsigned subtraction is performed in association with the set-on-less-than-unsigned case, if the Cout signal is de-asserted, then an overflow occurs when subtracting operand B from operand A ( A - B ), indicating the operation yields a result that is less than zero ( A < B ). If the unsigned subtraction produces an asserted Cout signal, subtracting operand B from operand A ( A - B ), indicated the operation yields a result greater than zero ( A > B ).
Based on the analysis described above, Table 8 below describes the truth table specification for the 32-bit comparison logic unit (CLU).
Comparison Type ALUOp[1:0]^ ASign^ BSign^ SumSign^ Cout^ CompareOut[31:0] NOT USED 00 x^ x^ x^ x^ 0x NOT USED 01 x^ x^ x^ x^ 0x
Set On Less Than ( SLT )
11 0 0 0 x 0x 11 0 0 1 x 0x 11 1 1 0 x 0x 11 1 1 1 x 0x 11 0 1 x x 0x 11 1 0 x x 0x Set On Less Than Unsigned ( SLTU )
10 x x x 0 0x 10 x x x 1 0x
Table 8: Interface and Functional Specification of the 32-bit CLU
The Complete 32-bit pMIPS ALU
With all four sub-components thoroughly defined and specified: BLU, LSU, ASU, and CLU, a block diagram of the 32- bit pMIPS ALU is provided in Figure 4.
Figure 4: The Complete 32-bit pMIPS ALU
The 32-bit pMIPS ALU can be implemented by utilizing the four sub-components in association with a 32-bit, 4-to- multiplexer based on the ALU operation code values. The 4-to-1 multiplexer is controlled by the upper two-bits ( ALUOp[3:2] ) of the ALU operation code. The lower two-bits ( ALUOp[3:2] ) of the ALU operation code is tied to each of the four sub-components. The unmodified overflow ( V ) and carry-out ( C ) flags are produced by the 32-bit ASU and provided to the overflow carry unit (OCU) for decoding based on MIPS specifications. The final flag, the zero flag ( Z ), is produced by taking the output of the 4-to-1 multiplexer and feeding the signal to the 32-bit zero detection unit (ZDU), as shown in Figure 4. Finally, notice that the 32-bit LSU’s 5-bit shamt input is tied to the lower 5-bits of operand A. This is done to facilitate certain aspects of the pMIPS datapath concerning shift operations. The reason as to why this is done will become clear in subsequent laboratory assignments.
Port Mode Type Default Size Description X (^) Input STD_LOGIC_VECTOR (^) N/A 32 Input operand Shamt (^) Input STD_LOGIC_VECTOR (^) N/A 5 Shift amount ALUOp (^) Input STD_LOGIC_VECTOR (^) N/A 2 Shift operation selector based on Table 4 ShiftOut (^) Output STD_LOGIC_VECTOR (^) N/A 32 Appropriately shifted result
Table 11: Interface specification for the 32-bit LSU Use instances of the 32-bit LSL, RSL, and RSA logic circuits as components. Additionally, utilize 32-bit, 2-to- multiplexers. Name the top-level design file lsu_32bit.vhd.
Task 3
(a) Implement, functionally simulate, and validate a 16-bit CLA using a structural architecture model. The 16-bit CLA interface specification is shown in Table 12. Use instances of the 4-bit CLA and the 4-bit LCU. Name the top-level design file cla_16bit.vhd.
Port Mode Type Default Size Description A, B (^) Inputs STD_LOGIC_VECTOR (^) N/A 16 The first and second input operands to the CLA Cin (^) Input STD_LOGIC (^) N/A 1 Initial carry input Sum (^) Output STD_LOGIC_VECTOR (^) N/A 16 The sum produced by the CLA Cout (^) Output STD_LOGIC (^) N/A 1 The final carry out G, P (^) Outputs STD_LOGIC (^) N/A 1,1 Group generate and group propagate signals
Table 12: Interface Specification of the 16-bit CLA
(b) Implement, functionally simulate, and validate a 32-bit CLA using a structural architecture model. The 32-bit CLA interface specification is shown in Table 13. Use two instances of the 16-bit CLA configured with a ripple carry architecture. Name the top-level design file cla_32bit.vhd.
Port Mode Type Default Size Description A, B (^) Inputs STD_LOGIC_VECTOR (^) N/A 32 The first and second input operands Cin (^) Input STD_LOGIC (^) N/A 1 Initial carry input Sum (^) Output STD_LOGIC_VECTOR (^) N/A 32 The sum Cout (^) Output STD_LOGIC (^) N/A 1 The final carry out
Table 13: Interface Specification of the 32-bit CLA
(c) Implement, functionally simulate, and validate a 32-bit ASU using a combination of structural and dataflow architecture modeling. The 32-bit ASU interface specification is shown in Table 14. Use a 32-bit CLA and the Overflow Detection Unit (ODU) as components. Model the 32-bit XOR gate using a VHDL FOR-GENERATE statement. Name the top-level design file asu_32bit.vhd.
Port Mode Type Default Size Description A, B (^) Inputs STD_LOGIC_VECTOR (^) N/A 32 The first and second input operands ALUOp (^) Input STD_LOGIC_VECTOR (^) N/A 2 Selects between the four arithmetic operations. Sum (^) Output STD_LOGIC_VECTOR (^) N/A 32 The sum Cout (^) Output STD_LOGIC (^) N/A 1 The carry out flag (C) Overflow (^) Output STD_LOGIC (^) N/A 1 The overflow flag (V)
Table 14: Interface Specification of the 32-bit ASU
(d) Implement, functionally simulate, and validate the modified overflow carry unit (OCU) using dataflow architecture modeling. The OCU interface specification is shown in Table 15. Utilize the functional specification of the OCU as specified in Table 6 for the implementation. Name the top-level design file ocu.vhd.
Port Mode Type Default Size Description ALUOp (^) Input STD_LOGIC_VECTOR (^) N/A 4 Selects between the four arithmetic operations. Overflow (^) Input STD_LOGIC (^) N/A 1 Overflow flag (V) from 32-bit ASU Cout (^) Input STD_LOGIC (^) N/A 1 Carry flag (C) from the 32-bit ASU V (^) Output STD_LOGIC (^) N/A 1 The modified overflow flag (V) based on Table 6 C (^) Output STD_LOGIC (^) N/A 1 The modified carry flag (C) based on Table 6
Table 15: Interface Specification of the Modified Overflow Carry Unit (OCU)
Task 4
Implement, functionally simulate, and validate the 32-bit comparison logic unit (CLU) using a behavioral architecture model. The interface and functional specification is indicated in Table 8. Utilize VHDL conditional or selected signal assignment statements. Name the top-level design file clu_32bit.vhd.
Task 5
Implement, functionally simulate, and validate the full 32-bit pMIPS ALU in Figure 4 using structural architectural modeling. The interface specification is indicated in Table 1. Use an instance of the 32-bit BLU, 32-bit ASU, 32-bit LSU, 32-bit Zero Detection Unit (ZDU), and a 32-bit, 4-to-1 multiplexer. Name the top-level design file alu_32bit.vhd.
Turn in all circuit schematics and/or block diagrams, logic equations, commented VHDL source code, Quartus II simulation waveform files, and answers to all questions required by this laboratory assignment using the ECE 371 laboratory report format.