Docsity

Laboratory Assignment 3: Implementing Combinational Logic Blocks II in pMIPS using VHDL, Lab Reports of Microprocessors

Partial preview of the text

Download Laboratory Assignment 3: Implementing Combinational Logic Blocks II in pMIPS using VHDL and more Lab Reports Microprocessors in PDF only on Docsity!

LABORATORY ASSIGNMENT # 3

pMIPS Combinational Logic Blocks II

Extender, Hex-to-7-Segment Decoder, Comparator, and 8-bit ASU

Spring 2009

Due Date: February 16th, 2009

ECE 371: Microprocessor Systems Laboratory

Department of Electrical and Computer Engineering

School of Engineering, Mathematics, & Sciences

Purdue University – Calumet

OBJECTIVE

The objectives of this laboratory assignment are to

  • Emphasize behavioral architectural modeling of digital circuits and systems through the use of conditional and selected signal assignment statements in VHDL.
  • Introduce the commonly used VHDL packages to facilitate behavioral modeling of digital circuits and systems.
  • Define and apply zero and sign extension concepts in the design of a parametric extension logic unit (ELU).
  • Implement a hex-to-7-segment decoder/driver to provide for a “user interface” for future FPGA programming
  • Implement a parametric two’s complement signed comparator and zero detection unit (ZDU)
  • Define and implement an 8-bit carry look-ahead addition/subtraction unit (ASU) with overflow detection

REFERENCES

  • Computer Organization and Design: The Hardware Software Interface, 4/e by David A. Patterson and John L. Hennessy, Morgan Kaufmann, 2008.
  • Fundamentals of Digital Logic with VHDL Design, 3/e by Stephen Brown and Zvonko Vranesic, McGraw Hill,

BACKGROUND

Sign Extension

Since binary integers have a fixed length, a small problem arises when having to convert an m-bit signed binary integer to an n-bit signed binary integer, given n > m. This problem can be solved via sign extension. Sign extension is the operation of increasing the number of bits of a binary number while preserving the number's sign (positive/negative). Sign extension is accomplished by appending binary digits to the most significant bits of the number, following a procedure dependent on the signed number representation used.

To sign extend an m-bit two’s complement binary number to an n-bit two’s complement binary number, given n > m, copy the sign bit of the m-bit number and append it to the original binary number until the m-bit number contains n bits. For example, -32 10 in 8-bit two’s complement format is 1110_0000 2 ( 0xE0 ). To sign extend this value to 16- bits, copy the MSB (a binary “1”) and append it to the MSB of -32 10 until 16-bits are produced. Therefore, -32 10 in 16- bit two’s complement format is 1111_1111_ 1 110_0000 2 ( 0xFFE0 ).

Zero Extension

When the need arises to represent an m-bit unsigned binary number to n-bits, where n > m, there is no need to sign extend, since the binary number is assumed to be positive. In this case, a zero extension operation is required. To zero extend an m-bit, unsigned binary number to n-bits, pad the MSBs of the m-bit number with zeros until it contains n- bits. For example, 32 10 in 8-bit two’s complement format is 0010_0000 2 ( 0x20 ). To zero extend this value to 16- bits, append zeros to the MSB of 32 10 until you have 16-bits. Therefore, 32 10 in 16-bit two’s complement format is 0000_000_0010_0000 2 ( 0x 0020 ).

An 8-bit Carry Look-ahead Adder (CLA)

To reduce the propagation delay bottleneck of a ripple-carry adder, engineers developed a carry look-ahead adder (CLA). The CLA uses the 4-bit LCU and partial full adders (PFAs), both developed in the previous two laboratory assignments. The LCU produces the four intermediate carries in parallel by utilizing more hardware. Each carry is computed by an independent, 2-level AND/OR circuit, within the LCU. The LCU is used in tandem with the PFAs to produce the sum. A 4-bit carry look-ahead adder (CLA) is shown in Figure 1.

bit CLA based on two’s complement binary arithmetic.

An 8-bit Carry Look-ahead Addition/Subtraction Unit (ASU)

Subtraction is the same as “adding the negative”. Every time subtraction is performed, operand B must be negated and then added to operand A. The easiest way to negate a two’s complement number is to invert all of the bits of the number, and then add “1” to the negated bits. This produces the two’s complement negative of the binary number. To negate all 8-bits, an 8-bit inverter can be tied to the B input of the 8-bit CLA and a “1” can be “injected” into the Cin input. This injection adds the “1” required for proper two’s complement negation. However, using inverters is not feasible, since we would need two 8-bit CLA’s, one for addition without inverters, and another configured for 8-bit subtraction, utilizing inverters and the Cin injection. Is there a way to use one 8-bit CLA to perform both addition and subtraction?

In order to use one 8-bit CLA to perform both addition and subtraction, the single 8-bit CLA would need to be controlled as both an addition and subtraction unit. For subtraction, input B should be inverted and input Cin should be preset to a logic one. In the case of addition, no inversion should take place and Cin would be pre-set to logic zero. To accomplish this, an XOR gate can be used to control the inversion of operand B of the adder. If one of the inputs to the XOR gate is always zero, the output of the XOR gate will always be the same as the other input. If one of the inputs of the XOR gate is a logic one, the output of the XOR gate will always be the inverted value of the other input. This is shown in Figure 3.

Figure 3: XOR Gate with one of the Inputs Used as a Bit-Inversion Controller

An 8-bit CLA-based addition-subtraction unit (ASU) can be designed using an 8-bit XOR gate (or eight XOR gates in parallel) with one of the inputs of each of the XOR gates tied to a single-bit control signal that controls the addition/subtraction operation, as shown in Figure 4.

Figure 4: An 8-bit, CLA-based Addition/Subtraction Unit (ASU) with Arithmetic Overflow Detection

The control signal, Sub , is set to a 1 and is injected into the Cin input to invert all the bits and to preset the Cin input to logic high, thus performing subtraction. To perform addition, the Sub signal is set to 0 which presets the Cin signal to a logic low and does not invert input B , thus performing ordinary addition.

Additionally, Figure 4 above shows a logic block that detects two’s complement arithmetic overflow. Two’s complement arithmetic overflow occurs when the result of the addition/subtraction cannot be represented in the amount of bits available for the sum/difference. A verbal description of the necessary conditions required to produce

two’s complement arithmetic overflow are described in Figure 5.

When adding two numbers, arithmetic overflow occurs when the sign of the two operands is the same and the result of the operation differs in sign from the operand signs. Arithmetic overflow does not occur when the signs of the operands differ.

Figure 5: Verbal Description of Conditions Required to Produce Two’s Complement Arithmetic Overflow

PROCEDURE

Task 1

(a) Implement, functionally simulate, and validate a parameterized extension logic unit (ELU) that extends an n-bit input to an m-bit output, where n < m, using a behavioral architecture model. The interface specification for the ELU is described in Table 1.

Port Mode Type Default Size Description

IN_SIZE (^) Generic POSITVE (^) 4 N/A Bit-length of the input

OUT_SIZE (^) Generic POSITIVE (^) 12 N/A Bit-length of the output

ZERO_EXTEND (^) Generic BOOLEAN TRUE (^) N/A Zero extend when true, else sign-extend

DataIn (^) Input STD_LOGIC_VECTOR (^) N/A IN_SIZE (^) Value requiring extension

DataOut (^) Output STD_LOGIC_VECTOR (^) N/A OUT_SIZE (^) Extended version of input

Table 1: Interface Specification of the Parameterized n-bit Extender Component

Use a VHDL GENERIC statement with the two generic parameters indicated in Table 1. Additionally, use a VHDL concatenation operator ( & ). Finally, utilize the VHDL IF-GENERATE statement to make the decision as to which type of hardware to create based on the ZERO_EXTEND Boolean parameter. Name the top-level design file extender_nbit.vhd. Hint: Use the VHDL OTHERS keyword to assign the output.

(b) Implement, functionally simulate, and validate a parameterized extension logic unit (ELU) that extends an n-bit input to an m-bit output, where n < m, using a structural architecture model. The interface specification for the ELU is described in Table 2.

Port Mode Type Default Size Description IN_SIZE (^) Generic POSITIVE (^) 8 N/A Bit-length of the input OUT_SIZE (^) Generic POSITIVE (^) 16 N/A Bit-length of the output DataIn (^) Input STD_LOGIC_VECTOR (^) N/A IN_SIZE (^) Value requiring extension

SignExtSel (^) Input STD_LOGIC (^) N/A 1-bit Sign extends DataIn when asserted else zero extends DataIn DataOut (^) Output STD_LOGIC_VECTOR (^) N/A OUT_SIZE (^) Extended version of DataIn

Table 2: Interface Specification of the Extension Logic Unit (ELU)

Use an instance of a k-bit 2-to-1 multiplexer along with two instances the n-bit extension logic unit (ELU) developed in part (a). One instance of the n-bit ELU should be configured to always sign extend while the other instance should be configured to always zero extend. Name the top-level design file elu_nbit.vhd.

Port Mode Type Default Size Description

IN_SIZE (^) Generic POSITIVE (^) 8 N/A The bit-length of the input data

Data (^) Input STD_LOGIC_VECTOR (^) N/A IN_SIZE (^) The data that is tested against 0x

Zero (^) Output STD_LOGIC (^) N/A 1-bit Only asserted high when Data == 0x

Table 5: Interface Specification of the Zero Detection Unit (ZDU)

Use the n-bit comparator as a component along with the VHDL CONSTANT statement to represent the n-bit zero value. Utilize VHDL’s GENERIC statement with parameters and default values as indicated in Table 5. Finally, use the VHDL OPEN keyword to map any unutilized output ports. Name the top-level design file zdu_nbit.vhd.

Task 4 (a) Implement, functionally simulate, and validate the 4-bit CLA in Figure 1 using a structural architecture model. Use the full-adder and the 4-bit LCU as components. Table 6 shows the interface specification of the 4-bit CLA. Name the top-level design file cla_4bit.vhd.

Port Mode Type Default Size Description A (^) Input STD_LOGIC_VECTOR (^) N/A 4-bits The first input (addend) to the CLA B (^) Input STD_LOGIC_VECTOR (^) N/A 4-bits The second input (augend) to the CLA Cin (^) Input STD_LOGIC (^) N/A 1-bits Initial carry input Sum (^) Output STD_LOGIC_VECTOR (^) N/A 4-bits The sum produced by the CLA Cout (^) Output STD_LOGIC (^) N/A 1-bits The final carry out G (^) Output STD_LOGIC (^) N/A 1-bits Group generate signal P (^) Output STD_LOGIC (^) N/A 1-bits Group propagate signal

Table 6: Interface Specification for the 4-bit CLA

(b) Implement, functionally simulate, and validate the 8-bit CLA in Figure 2 using a structural architecture model. Use the 4-bit CLA as component and use the VHDL OPEN keyword to map any output ports of the 4-bit CLA that are not used. Table 7 shows the interface specification of the 8-bit CLA. Name the top-level design file as cla_8bit.vhd.

Port Mode Type Default Size Description A (^) Input STD_LOGIC_VECTOR (^) N/A 8-bits The first input (addend) to the CLA B (^) Input STD_LOGIC_VECTOR (^) N/A 8-bits The second input (augend) to the CLA Cin (^) Input STD_LOGIC (^) N/A 1-bit Initial carry input Sum (^) Output STD_LOGIC_VECTOR (^) N/A 8-bits The sum produced by the CLA Cout (^) Output STD_LOGIC (^) N/A 1-bits The final carry out

Table 7: Interface Specification for the 8-bit CLA

(c) Design, implement, functionally simulate, and validate the overflow detection unit (ODU) circuit block in Figure 4 using a dataflow architecture model in VHDL. Use Figure 5 to develop a truth table and minimum sum of product (SOP) equations to synthesize the overflow detection logic. Name the top-level design file odu.vhd.

(d) Implement, functionally simulate, and validate the 8-bit CLA-based ASU in Figure 4 using a combination of dataflow and structural architecture models. Table 8 provides the interface specification to the 8-bit ASU.

Port Mode Type Default Size Description A (^) Input STD_LOGIC_VECTOR (^) N/A 8-bits The first input (addend) to the ASU B (^) Input STD_LOGIC_VECTOR (^) N/A 8-bits The second input (augend) to the ASU Sub (^) Input STD_LOGIC (^) N/A 1-bit Subtract when asserted high, else add Sum (^) Output STD_LOGIC_VECTOR (^) N/A 8-bits The result produced by the ASU V (^) Output STD_LOGIC (^) N/A 1-bit Indicates overflow when asserted high. Cout (^) Output STD_LOGIC (^) N/A 1-bits Indicates a carry-out from MSB when asserted high.

Table 8: Interface Specification of the 8-bit ASU

Use the 8-bit CLA and ODU as components. Additionally, use dataflow modeling along with a VHDL FOR- GENERATE statement to model the 8-bit XOR gates using “copies” of the 1-bit Sub control signal. Name the top- level design file asu_8bit.vhd.

DELIVERABLES

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.