Signed Arithmetic TYWu. Verilog 2001 Verilog 1995 provides only one signed data type, integer. Verilog 2001 provides a very rich set of new signed data.

Slides:



Advertisements
Similar presentations
UNIT 8: Synthesis Basics
Advertisements

ECE2030 Introduction to Computer Engineering Lecture 13: Building Blocks for Combinational Logic (4) Shifters, Multipliers Prof. Hsien-Hsin Sean Lee School.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Workshop Topics - Outline
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
B. RAMAMURTHY Hardware Description Language 8/2/
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See: P&H Chapter 2.4, 3.2, B.2, B.5, B.6.
Multiplying Integers. Warm Up 1.9 x 3 =5. 6 x 9 = 2.7 x 10 =6. 10 x 23 = 3.9 x 8 =7. 9 x 9 = 4.15 x 10 =8. 10 x 20 =
+ CS 325: CS Hardware and Software Organization and Architecture Exam 1: Study Guide.
ALGEBRA 1 Operations with Integers
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
Rules of Integers. Positive numbers are numbers that are above zero. Negative numbers are numbers below zero.
Dr. Bernard Chen Ph.D. University of Central Arkansas
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Lecture 5.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Scientific Notation.
Computers Organization & Assembly Language
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 5.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
Workshop Topics - Outline
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Fixed & Floating Number Format Dr. Hugh Blanton ENTC 4337/5337.
Cougar Time. Adding Negative Numbers  What are the two rules for adding integers?  Same Signs = Add and keep the sign  Different Signs = Find the absolute.
CS 105 “Tour of the Black Holes of Computing” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Operations with Decimals
Arithmetic Operations
CS 151: Digital Design Chapter 4: Arithmetic Functions and Circuits
Unit - 3 NUMBER SYSTEM AND CODES
Number Representation (Part 2) Computer Architecture (Fall 2006)
Unit 1 Rational Numbers Integers.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Add & Subtract. Addition Add bit by bit from right to left Ex 5+6 or (5)0111 (7) (6)OR (3) 1011 (11)1010 (10)
Representing Positive and Negative Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Integer Representations and Arithmetic
CS213 Integers Topics Numeric Encodings Programming Implications
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Hardware Description Language
332:437 Lecture 10 Verilog Language Details
Hardware Description Language
332:437 Lecture 10 Verilog Language Details
COE 202 Introduction to Verilog
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
Hardware Description Language
Homework Homework Continue Reading K&R Chapter 2 Questions?
332:437 Lecture 10 Verilog Language Details
Hardware Description Language
ECE 352 Digital System Fundamentals
Computer Organization COMP 210
Hardware Description Language
Presentation transcript:

Signed Arithmetic TYWu

Verilog 2001 Verilog 1995 provides only one signed data type, integer. Verilog 2001 provides a very rich set of new signed data types. However, there are issues when performing operations –sign extension –truncation or rounding, –saturation, addition, and multiplication with signed values.

Decimal to 3-bit Signed Table

Type Casting The casting operators, $unsigned and $signed, only have effect when casting a smaller bit width to a larger bit. –A = $unsigned(B) will zero fill B and assign it to A. –Casting using $signed(signal_name) will sign extend the input. For example, A = $signed(B). –If the sign bit is X or Z the value will be sign extended using X or Z, respectively.

Type Casting Assigning to a smaller bit width signal will simply truncate the necessary MSB’s as usual. Casting to the same bit width will have no effect other than to remove synthesis warnings.

Signed Based Values 2 represented as a 3-bit signed hex value would be specified as 3’sh2. Somewhat confusing is specifying negative signed values. The value -4 represented as a 3-bit signed hex value would be specified as -3’sh4. A decimal number is always signed.

Signed Addition Example for Verilog 1995 –Adding two values that are n-bits wide will produce a n+1 bit wide result module add_signed_1995 ( input [2:0] A, input [2:0] B, output [3:0] Sum ); assign Sum = {A[2],A} + {B[2],B}; endmodule // add_signed_1995 Manually Add

Signed Addition Example for Verilog 2001 –We can use the new signed type module add_signed_2001 ( input signed [2:0] A, input signed [2:0] B, output signed [3:0] Sum ); assign Sum = A + B; endmodule // add_signed_2001 Automatic!

Signed Addition Unsigned Example module add ( input [2:0] A, input [2:0] B, output [3:0] Sum ); assign Sum = A + B; endmodule

Signed Multiplication Example 3’b101 == -3 -1* * *2 0

Signed Multiplication Example for Verilog 1995 module mult_signed_1995 ( input [2:0] a, input [2:0] b, output [5:0] prod ); wire [5:0] prod_intermediate0; wire [5:0] prod_intermediate1; wire [5:0] prod_intermediate2; wire [2:0] inv_add1;

Signed Multiplication assign prod_intermediate0 = b[0] ? {{3{a[2]}}, a} : 6'b0; assign prod_intermediate1 = b[1] ? {{2{a[2]}}, a, 1'b0} : 6'b0; // Do the invert and add1 of a. assign inv_add1 = ~a + 1'b1; assign prod_intermediate2 = b[2] ? {{1{inv_add1[2]}}, inv_add1, 2'b0} : 6'b0; assign prod = prod_intermediate0 + prod_intermediate1 + prod_intermediate2; endmodule

Signed Multiplication Example for Verilog 2001 module mult_signed_2001 ( input signed [2:0] a, input signed [2:0] b, output signed [5:0] prod); assign prod = a*b; endmodule

Advanced Topics Recall the rule that if any operand of an operation is unsigned the entire operation is unsigned. When synthesized the following warning occurs:signed to unsigned conversion occurs. (VER-318). Now if we multiply –3 (3’b101) by 2 (3’b010) as usual with this code we get 0xA (6’b001010).