How To Write A Full-Dual Adder/Subtractor In A Microsoft Computer Program

Similar documents
Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

5 Combinatorial Components. 5.0 Full adder. Full subtractor

CSE140 Homework #7 - Solution

Binary Adders: Half Adders and Full Adders

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

Sistemas Digitais I LESI - 2º ano

Let s put together a Manual Processor

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

DEPARTMENT OF INFORMATION TECHNLOGY

ECE410 Design Project Spring 2008 Design and Characterization of a CMOS 8-bit Microprocessor Data Path

VHDL Test Bench Tutorial

Lecture 8: Binary Multiplication & Division

Systems I: Computer Organization and Architecture

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Step : Create Dependency Graph for Data Path Step b: 8-way Addition? So, the data operations are: 8 multiplications one 8-way addition Balanced binary

Understanding Logic Design

Digital Design with VHDL

The string of digits in the binary number system represents the quantity

Multipliers. Introduction

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Xilinx ISE. <Release Version: 10.1i> Tutorial. Department of Electrical and Computer Engineering State University of New York New Paltz

EXPERIMENT 4. Parallel Adders, Subtractors, and Complementors

Computer organization

LAB #3 VHDL RECOGNITION AND GAL IC PROGRAMMING USING ALL-11 UNIVERSAL PROGRAMMER

VHDL GUIDELINES FOR SYNTHESIS

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

Quartus II Introduction for VHDL Users

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Adder.PPT(10/1/2009) 5.1. Lecture 13. Adder Circuits

Using Xilinx ISE for VHDL Based Design

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

An Effective Deterministic BIST Scheme for Shifter/Accumulator Pairs in Datapaths

16-bit ALU, Register File and Memory Write Interface

Combinational Logic Design

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

12. A B C A B C A B C 1 A B C A B C A B C JK-FF NETr

CHAPTER 3 Boolean Algebra and Digital Logic

COMBINATIONAL CIRCUITS

ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

exclusive-or and Binary Adder R eouven Elbaz reouven@uwaterloo.ca Office room: DC3576

Floating Point Fused Add-Subtract and Fused Dot-Product Units

Solution for Homework 2

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

Flip-Flops, Registers, Counters, and a Simple Processor

MICROPROCESSOR AND MICROCOMPUTER BASICS

(Refer Slide Time: 00:01:16 min)

NEW adder cells are useful for designing larger circuits despite increase in transistor count by four per cell.

CMOS Binary Full Adder

Digital Design with Synthesizable VHDL

Binary full adder. 2-bit ripple-carry adder. CSE 370 Spring 2006 Introduction to Digital Design Lecture 12: Adders

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Two's Complement Adder/Subtractor Lab L03

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

The 104 Duke_ACC Machine

Counters are sequential circuits which "count" through a specific state sequence.

Lecture 2. Binary and Hexadecimal Numbers

Lecture N -1- PHYS Microcontrollers

Coding Guidelines for Datapath Synthesis

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

CS 61C: Great Ideas in Computer Architecture Finite State Machines. Machine Interpreta4on

CPEN Digital Logic Design Binary Systems

Digital Systems Design. VGA Video Display Generation

CHAPTER IX REGISTER BLOCKS COUNTERS, SHIFT, AND ROTATE REGISTERS

3.Basic Gate Combinations

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Microprocessor & Assembly Language

Systems I: Computer Organization and Architecture

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

1 Classical Universal Computer 3

Combinational-Circuit Building Blocks

Z80 Instruction Set. Z80 Assembly Language

Integer Arithmetic IP Cores User Guide

Designing Digital Circuits a modern approach. Jonathan Turner

Registers & Counters

An Example VHDL Application for the TM-4

CONTENTS PREFACE 1 INTRODUCTION 1 2 NUMBER SYSTEMS AND CODES 25. vii

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

9/14/ :38

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

Binary Numbering Systems

FPGA. AT6000 FPGAs. Application Note AT6000 FPGAs. 3x3 Convolver with Run-Time Reconfigurable Vector Multiplier in Atmel AT6000 FPGAs.

MACHINE ARCHITECTURE & LANGUAGE

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Lab 1: Full Adder 0.0

Lecture #21 April 2, 2004 Relays and Adder/Subtractors

Number Representation

CNC FOR EDM MACHINE TOOL HARDWARE STRUCTURE. Ioan Lemeni

earlier in the semester: The Full adder above adds two bits and the output is at the end. So if we do this eight times, we would have an 8-bit adder.

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, The Binary Adder

List of Experiment. 8. To study and verify the BCD to Seven Segments DECODER.(IC-7447).

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

State Machines in VHDL

Number and codes in digital systems

Lab 7: VHDL 16-Bit Shifter

High Speed and Efficient 4-Tap FIR Filter Design Using Modified ETA and Multipliers

LFSR BASED COUNTERS AVINASH AJANE, B.E. A technical report submitted to the Graduate School. in partial fulfillment of the requirements

Transcription:

ECE 3401 Lecture 9 VHDL for Arithmetic Functions and Circuits Outline Arithmetic Functions and Circuits: operate on binary vectors, use the same sub-function in each bit position Adders Multipliers Others 1

Adder/Subtractor Basic building block for Computer-Arithmetic and Digital Signal Processing Implementation: Schematic Capture Implementation VHDL Implementation Adder Design Half-adder (HA): a 2-input bitwise addition FB Full-adder (FA): a 3-input bit-wise addition FB Ripple carry adder: an iterative array to perform binary addition, full adders chained together Carry-look-ahead adder: a hierarchical adder to improve performance Propagate and generate logic 2

Functional Block Implementation Half adder: S=X + Y X Y C=X Y Full adder: S=X + Y + C in C=XY + (X + Y)C in =G+P C in XY: carry generate G X + Y: carry propagate P S C X Y C Half Adder P G G C in Half Adder S X C2 P Y S C in C Ripple Carry Adder A 4-bit ripple carry adder made from four 1-bit full adder Worst case delay - #bits x full adder delay The longest path is from A 0 /B 0 through the circuit to S 3 Or from C 0 through the circuit to C 4, 3

Carry Lookahead Adder From the full-adder implementation, two signal conditions: generate G and propagate P. P i = A i + B i S i = P i + C i G i = A i B i C i+1 = G i + P i C i In order to reduce the length of the carry chain, C i is changed to a more global function spanning multiple cells C 1 =G 0 +P 0 C 0 C 2 =G 1 +P 1 C 1 =G 1 +P 1 (G 0 +P 0 C 0 ) =G 1 +P 1 G 0 +P 1 P 0 C 0 =G 0-2 + P 0-2 C 0 C 3 =G 2 +P 2 C 2 =G 2 +P 2 (G 1 +P 1 G 0 +P 1 P 0 C 0 ) =G 2 +P 2 G 1 +P 2 P 1 G 0 +P 2 P 1 P 0 C 0 = G 0-3 +P 0-3 C 0 C4=G 3 +P 3 C 3 =G 3 +P 3 (G 2 +P 2 G 1 +P 2 P 1 G 0 +P 2 P 1 P 0 C 0 ) =G 3 +P 3 G 2 +P 3 P 2 G 1 +P 3 P 2 P 1 G 0 +P 3 P 2 P 1 P 0 C 0 = G 0-4 +P 0-4 C 0 4

VHDL Description of a 4-bit CLA entity CLA4 is port (A, B: in bit_vector (3 downto 0); Ci: in bit; S: out bt_vector (3 downto 0); Co, PG, GG: out bit); end CLA4; architecture structure of CLA4 is component CPFullAdder port (X, Y, Cin: in bit; G, P, Sum: out bit); end component; component CLALogic is port (G, P: in bit_vector (3 downto 0); Ci: int bit; C: out bit_vector (3 downto 1); Co, FG, CG: out bit); end component; signal G, P: bit_vector (3 downto 0); signal C: bit_vector (3 downto 0); begin CarryLogic: CLALogic port map (G, P, Ci, C, Co, PG, GG); FA0: CPFullAdder port map (A(0), B(0), Ci, G(0), P(0), S(0)); FA1: CPFullAdder port map (A(1), B(1), C(1), G(1), P(1), S(1)); FA2: CPFullAdder port map (A(2), B(2), C(2), G(2), P(2), S(2)); FA1: CPFullAdder port map (A(3), B(3), C(3), G(3), P(3), S(3)); end structure; CLALogic entity CLALogic is port (G, P: in bit_vector (3 downto 0); Ci: in bit; C: out bit_vector (3 downto 1); Co, PG, GG: out bit); end CLALogic; architecture Equations of CLALogic is signal GG_int, PG_int: bit begin C(1)<=G(0) or (P(0) and Ci); C(2)<=G(1) or (P(1) and G(0) or (P(1) and P(0) and Ci); C(3)<=G(2) or (P(2) and P(1) and G(0) or (P(2) and P(1) and P(0) and Ci); PG_int<=P(3) and P(2) and P(1) and P(0); GG_int<=G(3) or (P(3) and G(2)) or (P(3) and P(2) and G(1)) or (P(3) and P(2) and P(1) and P(0) and G(0)); Co<=GG_int or (PG_int and Ci); PG<=PG_int; GG<=GG_int; end Equations; 5

Carry Lookahead Adder Example Extend to 16 bits, to have four 4-bit adders use one of the same carry lookahead circuits Delay Specifications NOT=1, XOR=Isolated AND=3, AND-OR=2 Longest delays: Ripple carry adder: =3+15*2+3=36 CLA=3+3*2+3=12 Schematic Capture & Macrofunctions Schematic Capture Most schematic capture tools include modules as macrofunctions or megafunctions that are useful for implementing some of the highly complex digital hardware such as adders, subtractors, multipliers, and dividers. Macrofunctions may be technology-dependent or technology independent A technology-dependent macrofunction is designed to suit a specific type of chip A technology-independent macrofunction can be implemented in any chip 6

Xilinx Unisim Library of Primitives and Macros Xilinx ISE XST system includes a library of primitives and macros called Unisim Many modules in the library are technology dependent. Most modules are parameterized, implying that it can be used in a variety of ways. More modules are available through CoreGenerator Xilinx Library Spartan-II http://toolbox.xilinx.com/docsan/xilinx5/data/docs/lib/ lib0024_8.html Core Generator IP Center on Xilinx.com Third party IP including Communication blocks - ethernet, ATM, encoders, etc. Arithmetic blocks - multipliers, comparators, adders, etc. Microprocessors - PowerPC, 68000, 8051, UARTs, etc. Bus Interfaces - PCI, HyperChannel, etc. Memories - CAMs, RAM interfaces, FIFOs, etc. Opencores.org Free, open source VHDL for many cores 7

16-bit adder/subtractor VHDL for 16-bit adder LIBRARY ieee; USE ieee.std_logic_1164.all; LIBRARY lpm; USE lpm.lpm_components.all; ENTITY adderlpm IS PORT ( Cin : IN STD_LOGIC; X, Y : IN STD_LOGIC_VECTOR (15 DOWNTO 0); S : OUT STD_LOGIC_VECTOR (15 DOWNTO 0); Cout : OUT STD_LOGIC; Overflow : OUT STD_LOGIC); END adderlpm; ARCHITECTURE addsoft OF adderlpm IS BEGIN instance: lpm_add_sub GENERIC MAP (LPM_WIDTH => 16) PORT MAP (add_sub => 0, cin => Cin, dataa => X, datab => Y, result => S, cout => Cout, overflow=>overflow); END addsoft; 8

Timing diagram for adder Subtraction Subtraction (A-B) Unsigned: A B => A-B ; A<B => the difference A-B+2 n is subtracted from 2 n, a sign added before the result (2 n -X is taking the 2 s complement of X) Signed integer For binary numbers s a n-2 a 2 a 1 a 0 s=0 for positive numbers; s=1 for negative numbers Signed-magnitude: the n-1 digits are a positive magnitude Signed 2 s complement 9

2 s Complement Adder/Subtractor Subtraction can be done by adding 2 s complement For s=1, subtract, the 2 s complement of B is formed by using XORs to form the 1 s complement and adding the 1 applied to C 0 For s=0, add, B is passed through unchanged VHDL for adder/subtractor LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY addsubtract IS PORT ( S : IN STD_LOGIC; A, B : IN STD_LOGIC_VECTOR (3 DOWNTO 0); SO : OUT STD_LOGIC_VECTOR (3 DOWNTO 0); Cout : OUT STD_LOGIC); END adderlpm; ARCHITECTURE behavior OF addsubtract IS signal Sum : STD_LOGIC_VECTOR (4 downto 0); BEGIN with S select Sum <= A+B when 0 A-B+ 10000 when others; Cout <= Sum (4); SO <= Sum (3 downto 0); END behavior; 10

Multiply Multiply requires shifting the multiplicant to the left adding it to the partial sum. Requires a shift register as wide as the product and an accumulator for the partial and final product. 9 = 1001 (multiplicant) x13 = x 1101 (multiplier) 1001 +0000 = 01001 +1001 = 101101 +1001 117 = 1110101 Multiplier Here is a hardware description of a multiplier Multiplicand reg If B[0] is 1. load (add # to accumulator) Shift multiplicand reg left Shift multiplier reg right -> B[0] Repeat until done Multiplier reg B[0] + LD Accumulator 11

Multiplier Multiply VHDL Library unisim; Use unisim.vcomponents.all Architecture beh of mult is component MULT18X18 port( A : in std_logic_vector (17 downto 0); B : in std_logic_vector (17 downto 0); P : out std_logic_vector (35 downto 0) ); end component; begin U_MULT18X18 : MULT18X18 port map (A,B,P); end 12

Multiply Timing Diagram Division Division macros are not part of the Unisim library Multiply and Divide by power of 2 can be accomplished with a shifter 13

Other Arithmetic Functions Overflow detection: overflow occurs if n+1 bits are required to contain the results from an n-bit addition or subtraction Incrementing: counting up, A+1, B+4 Decrementing: counting down, A-1, B-4 Multiplication by constant: left shift Division by constant: right shift Zero fill: filling zero either at MSB or LSB end Extension: copy the MSB of the operand into the new positions Design by Contraction Contraction is a technique for simplifying the logic in a functional block to implement a different function Example: contraction of a ripple-carry adder to increment for 3 bits (set B=001) 14