Verilog - Representation of Number Literals



Similar documents
Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

2011, The McGraw-Hill Companies, Inc. Chapter 3

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

Binary Numbers. Binary Octal Hexadecimal

Lecture 11: Number Systems

CSI 333 Lecture 1 Number Systems

Lecture 2. Binary and Hexadecimal Numbers

Useful Number Systems

CPEN Digital Logic Design Binary Systems

Solution for Homework 2

Unsigned Conversions from Decimal or to Decimal and other Number Systems

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

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Base Conversion written by Cathy Saxton

Computer Science 281 Binary and Hexadecimal Review

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Numbering Systems. InThisAppendix...

COMPSCI 210. Binary Fractions. Agenda & Reading

Binary Representation

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

3. Convert a number from one number system to another

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

NUMBER SYSTEMS. 1.1 Introduction

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Number Representation

Systems I: Computer Organization and Architecture

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

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

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Section 1.4 Place Value Systems of Numeration in Other Bases

Chapter 4: Computer Codes

Chapter 2. Binary Values and Number Systems

Binary, Hexadecimal, Octal, and BCD Numbers

CS201: Architecture and Assembly Language

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Number and codes in digital systems

Number Systems. Introduction / Number Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Coding Guidelines for Datapath Synthesis

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Chapter 1: Digital Systems and Binary Numbers

BINARY CODED DECIMAL: B.C.D.

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

The programming language C. sws1 1

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

A Verilog HDL Test Bench Primer Application Note

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

NUMBER SYSTEMS. William Stallings

Pemrograman Dasar. Basic Elements Of Java

Regular Expression Syntax

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

2.2: Bitwise Logical Operations

Tamper protection with Bankgirot HMAC Technical Specification

Informatica e Sistemi in Tempo Reale

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Appendix B RCS11 Remote Communications

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Counting in base 10, 2 and 16

CE363 Data Communications & Networking. Chapter 6 Network Layer: Logical Addressing

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

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

MIDImplant micro MIDI-2-CV device version 3.8

Streaming Lossless Data Compression Algorithm (SLDC)

The Habit Programming Language: The Revised Preliminary Report

CCNA R&S: Introduction to Networks. Chapter 9: Subnetting IP Networks

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Floating point package user s guide By David Bishop (dbishop@vhdl.org)

CS321. Introduction to Numerical Methods

Lab 1: Full Adder 0.0

=

.NET Standard DateTime Format Strings

1.Eastron SDM220Modbus Smart Meter Modbus Protocol Implementation V1.0

ELEG3924 Microprocessor Ch.7 Programming In C

The Answer to the 14 Most Frequently Asked Modbus Questions

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

8 data bits, least significant bit sent first 1 bit for even/odd parity (or no parity) 1 stop bit if parity is used; 1 or 2 bits if no parity

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Technical Support Bulletin Nr.18 Modbus Tips

DATA_TYPE Values and Data File Storage Formats

Number Systems and Radix Conversion

Decimal to Binary Conversion

DATA INPUT METHODS OBJECTIVE QUESTIONS

IT:101 Cisco Networking Academy I Subnetting

Basic Logic Gates Richard E. Haskell

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

TCP/IP Cheat Sheet. A Free Study Guide by Boson Software, LLC

NUMBER SYSTEMS TUTORIAL

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

HOMEWORK # 2 SOLUTIO

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Transcription:

Verilog - Representation of Number Literals... And here there be monsters! (Capt. Barbossa) Numbers are represented as: <size> <signed><radix>value ( <> indicates optional part) size The number of binary bits the number is comprised of. Not the number of hex or decimal digits. Default is 32 bits. A separator, single quote, not a backtick signed Indicates if the value is signed. Either s or S can be used. Not case dependent Default is unsigned. radix Radix of the number b or B : binary o or O : octal h or H : hex d or D : decimal default is decimal

Verilog - Representation of Number Literals(cont.) Possible values for value are dependent on the radix Format Prefix Legal characters binary b 01xXzZ? octal o 0-7xXzZ? decimal d 0-9 hexadecimal h 0-9a-fA-FxXzZ? The underscore is a separator used to improve readability e.g.: 0010 1010 1110 0101 is easily read as 0x2AE5 The character x or X represents unknown The character z or Z represents high impedance The character? or? same as Z (high impedance) The character? is also don t care to synthesis

Verilog - Representation of Number Literals(cont.) If prefix is preceded by a number, number defines the bit width If no prefix given, number is assumed to be 32 bits Verilog expands <value > to fill given <size> working from LSB to MSB. If <size> is smaller than value MSB s of value are truncated with warning (tool dependent) If <size> is larger than value MSB s of value are filled Regardless of MSB being 0 or 1, 0 filling is done Left-most Bit Expansion 0 0 extend 1 0 extend x X x or X extend z Z z or Z extend

Verilog - Representation of Number Literals(cont.) Some Examples: reg [7:0] v = 8 b1011; initial $displayb ("v signed =\t", v); //v = 00001011, MSBs filled with zeros reg [7:0] w = 3 b1011; initial $displayb ("w signed =\t", w); //w = 00000011, bit 3 truncated then 0 filled //generates Modelsim compile warning (Redundant digits in numeric literal) //Runs without warning or error

Verilog - Representation of Number Literals (cont.) Literal numbers may be declared as signed: 4shf 4 bit number (1111) interpreted as a signed 2s complement value Decimal value is -1. Signed values are not necessarily sign extended because the sign bit is the MSB of the size, not the MSB of the value. 8 ha //unsigned value extends to: 00001010 8 sha //signed value extends to: 00001010 If the MSB of the size is one and is signed, sign extension will occur. reg [11:0] p1 = 4 sha; initial $displayb ("p1 signed =\t", p1); //p1 = 1111_1111_1010, bit 3 is the sign bit reg [11:0] p2 = 5 sha; initial $displayb ("p2 signed =\t", p2); //p2 = 0000_0000_1010, bit 3 was the sign bit, but was lost in extension When the value is assgined to a bigger vector, the sign indication <s>, will force sign extension when the MSB of value is one. If a signed number such as 9shA6, (8 bits in 9 bit vector) is assigned to a bigger vector the sign bit is lost and is not sign extended. Beware!

Verilog - Representation of Number Literals (cont.) Literal numbers can also carry a sign: -4 sd15 This is equivalent to -(4 sd15) or -(-1) or 1. We need to be careful with how an explicit sign is interpreted. See the examples to follow.

Verilog - Representation of Number Literals (cont.) Some examples: module number_test; reg [11:0] a = 8 sha6; initial $displayb ("a=", a); // number 0xA6 is signed, MSB of size (7) is one, so its negative // so to produce the 12 bit result, its sign extended with 1 s, thus //a=1111_1010_0110 reg [11:0] b = 8 sh6a; initial $displayb ("b=", b); // signed number 0x6A has MSB (7) is zero, its positive // so to produce the 12 bit result, its sign extended with 0 s, thus // b=0000_0110_1010 reg [11:0] c = sha6; initial $displayb ("c=", c); //c is the signed number A6, but its MSB is zero as its 32 bits long // c=0000_1010_0110, not sign extended reg [11:0] d = sh6a; initial $displayb ("d=", d); //signed, unsized number 6A has MSB (31) zero so its positive: // 0000_0000_0000_0000_0000_0000_0110_1010 //assign the 32 bit value to 12 bits: // d=0000_0110_1010

Verilog - Representation of Number Literals (cont.) Some more examples: reg [11:0] e = -8 sha6; initial $displayb ("e=", e); //0xA6 is signed, expanded to 8 bits with MSB (7) one: 1010_0110 //negating this with a minus sign: (2 s compliment) : 0101_1010 //now assign with sign extension: e=0000_0101_1010 //i.e.; -(8 sha6) e=0000_0101_1010 reg [11:0] f = - sha6; initial $displayb ("f=", f); //0xA6 is signed, unsized, with MSB (31) zero, so its positive : // 0000_0000_0000_0000_0000_0000_1010_0110 //taking twos complement we get: // 1111_1111_1111_1111_1111_1111_0101_1010 //assigning to 12 bits (by truncation) we get // f=1111_0101_1010 reg [11:0] g = 9 sha6; initial $displayb ("g=", g); //0xA6 is signed with MSB (8) zero, so its positive: 0_1010_0110 //assign it to a 12-bit reg by sign extending: 0000_1010_0110 // g=0000_1010_0110 reg [11:0] h = 9 sh6a; initial $displayb ("h=", h); //0x6A is signed with MSB (8) zero, so its positive: 0_0110_1010 //assign it to a 12-bit reg by sign extending: 0000_0110_1010 // h=0000_0110_1010