FPGA design-digital representation (code + waveform)

Source: Internet
Author: User

In a digital logic system, there are only high voltage and low level. Therefore, it indicates that a number is only in the integer form, and there are three Representation Methods: original code representation (symbol plus absolute value), reverse code notation (symbol plus reverse code) and complement code notation (symbol plus complement ). These three methods are widely used in FPGA development.

1. Original code representation

The original code representation is a simple representation of the number of machines. It uses the sign-bit cascade absolute value to represent numbers. The highest bit is the sign bit. 0 indicates a positive number, and 1 indicates a negative number. The other part is the absolute value. The original code is generally expressed in binary format.

For example, if X1 = + 1010110 and X2 =-1001010, the original codes are 01010110 and 11001010 respectively.

The range of the original number is related to the binary number. When an 8-bit binary is used to represent the decimal original code, it indicates the range: the maximum value is 0.1111111, and its true value is about 0.99 in the 10-digit system; the minimum value is 1.1111111, the true value is about-0.99 in decimal format. When an integer is expressed as an 8-bit binary code, the value ranges from 01111111 to 127, and the true value is 11111111 in decimal format. The minimum value is 127, and the true value is-in decimal format.

In the original code representation method, there are two representation forms for 0, respectively marked as + 0 and-0. Taking 8-bit data as an example, the corresponding representation is: + 0 = 00000000,-0 = 10000000.

2. Reverse code representation

The reverse code can be obtained from the original code. If the number is a positive number, the reverse code is the same as the original code. If the number is a negative number, the reverse code is obtained for its original code (except the symbol bit.

For example, if X1 = + 1010110 and X2 =-1001010, the corresponding anti-code is 01010110 and 10110101.

3. complement Representation

The complement indicates the most widely used numeric representation in the mage's practice. The expression rules are as follows: if it is a positive number, the expression of the complement and reverse code is the same as that of the original code; if it is a negative number, the representation of the complement, reverse, and original codes is different.

The key between the anticode and the original code is that the complement code of the negative number is equal to the bitwise of the anticode plus 1.

4. Summary of various Representation Methods

The advantage of the original code is that it is convenient to perform multiplication and division operations, regardless of positive and negative numbers. The positive and negative signs of the result are determined by the symbol bit. If the addition rule is used, it is necessary to determine whether the two symbols are the same; if Subtraction is performed, you also need to determine the size of the absolute values of two numbers to reduce the number of large numbers.

The advantage of complement is that addition is convenient, and can be directly added regardless of the positive or negative number, and the symbol bit also participates in the operation.

Example: provides basic addition operations for various codeword notation and describes their respective features

(1) first, an example of the original code is given. () D indicates the decimal number. First, an example of the original code Subtraction is provided to complete the"1 + (-1) = 0".

(1) d + (-1) d = (0) d

If the reader directly uses the original code to complete the above operation, it will find that the problem occurs when the original code with the symbol bit is used for addition and subtraction. The data is represented in 8 bits as an example,

(00000001) ORIGINAL + (10000001) original = (10000001) original = (-2) d

The calculation result is incorrect. The problem is that, first, the negative symbol directly changes the calculated result symbol. Second, the absolute value is incorrect. This indicates that the original code cannot directly add positive and negative numbers.

(2) since the original code cannot sum up positive and negative numbers, can this operation be completed in the form of reverse code? Take "1 + (-1) = 0" as an example. The corresponding anti-code expression is as follows:

(00000000) + (11111110) = (11111111) = (-0) d

The problem is found on + 0 and-0, because there is no positive or negative score for the actual calculation. However, it indicates that the absolute value of the positive and negative values is correct after the inverse code is added. Therefore, the expression of positive and negative numbers must contain the characteristics of the inverse code.

(3) Finally, we provide a description of the complementary features. The negative complement is to add 1 to the reverse code, while the positive number remains unchanged. Taking 8-bit data as an example, (-128) D is replaced by (-10) d, so the range is [-128,127 ]. Intuitively, the complement Code eliminates (+ 0) and (-0), and has the anti-code feature. Can it complete positive and negative addition operations? The answer is yes. The following is an example.

(00000001) Fill + (11111111) Fill = (00000000) Fill = (0) d

Based on the above discussion, we can get a basic conclusion: only the complement code can correctly complete the plus and minus addition operations, and convert the subtraction operation to the addition operation, thus simplifying the operation rules.

However, for the multiplication operation, it is most convenient to calculate in the form of the original code. Below is an example.


Demonstration 1: multiplication of the original code-2*2 =-4

module mul(input clk,input rstn,input [7:0] a,input [7:0] b,output [14:0] q_mul,output reg [8:0] q_add,output reg[7:0] ra,    output reg[7:0] rb    );            reg [13:0] rmul;        always @(posedge clk or negedge rstn)    if(!rstn)    begin    q_add <= 0;    ra <= 0;    rb <= 0;        rmul <= 0;    end    else begin        //q_mul <= a*b;    if(a[7]==1)    ra = {a[7],~a[6:0] + 1};    else    ra = a;    if(b[7]==1)    rb = {b[7],~b[6:0] + 1};    else    rb = b;    rmul <= ra[6:0]*rb[6:0];            q_add <= {a[7],a} + {b[7],b};    end        assign q_mul = {a[7]^b[7],rmul};    endmodule



























FPGA design-digital representation (code + waveform)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.