x86 base number and data type

Source: Internet
Author: User
Tags numeric

We know that the number processed in the computer is organized and stored according to certain rules. Each of these numbers is organized by a specific encoding rule. However, it is not enough to have the organization rules of these numbers, and the operands of each instruction of the computer may have different data types. So what data types can the computer handle? In this chapter, we will look at the numbers and data types. number

The computer can handle a variety of information, the computer hardware to the data processing, can show a variety of information. Digital

The number is a basic counting symbol. There are 10 general-purpose numbers: 0,1,2,3,4,5,6,7,8,9. The number composed of these numbers is a decimal number.

Think of the numbers for each number of decimal. 1. Binary digits

Includes 0 and 1. 2. Octal digits

including 0,1,2,3,4,5,6,7. 3. Decimal digits

including 0,1,2,3,4,5,6,7,8,9. 4. hexadecimal digits

Includes 0,1,2,3,4,5,6,7,8,9 and letter a,b,c,d,e,f.

Each binary is represented as a base value in the corresponding number representation, such as: the base value of the binary is 2, the base value of the octal is 8, the base value of the decimal is 10, and the hexadecimal base value is 16. Binary number

Binary number is the basis of computer operations, regardless of the number of formats, in the computer is in the binary form of storage. A sequence of numbers consisting of binary digits is a binary number, as shown below.

In binary number combinations, each digit is called bit (bit) and can represent values 0 and 1. The base value of the binary number is 2, and in the sequence of n binary numbers, the value is

Value = (dn-1x2n-1) + (dn-2x2n-2) +...+ (d1x21) + (d0x20)

This is a mathematical formula. This value is a decimal value that we can easily identify. permutation of binary numbers

In everyday writing or expression, the leftmost bit is the highest. The number of bits is arranged from left to right, and the corresponding value is from high to low. But in the digital circuit of the machine, the high and low bits of the number can be arranged from left to right, or from right to left. This creates the concept of MSB and LSB.

What is MSB. What is an LSB.

Take a natural binary expression sequence on the 32-bit binary number as an example, the rightmost is bit 0, the leftmost is bit 31. Bit 0 is denoted by the LSB (Least significant bit, least significant bit), and bit 31 is represented by the MSB (most significant bit, the most significant bit).

The MSB is also used as the sign bit (1 is negative, 0 is positive), but in the unsigned number, the MSB is the highest bit of the number, and the LSB is the lowest bit of the number. Regardless of whether a number is arranged from left to right on the machine or from right to left, it is easy to describe the binary form with the concept of MSB and LSB. small end sequence and big endian

Binary number in the organization of the computer storage, the address from low to high position corresponds to two kinds of arrangement.

① from LSB to MSB, this is the small-endian (Little-endian) platoon.

② from the MSB to the LSB, which is the big-endian (Big-endian) platoon.

In the x86/x64 system, a small-order storage format is used, namely: the MSB corresponds to the high position of the memory address, and the LSB corresponds to the low of the memory address.

In some RISC (simplified instruction set computer) systems, typical such as the POWER/POWERPC series, use the big-endian sequence. That is, in the low-to-high address bit, the MSB to LSB is stored in turn. That is: The MSB is stored at the low level of the memory address and the LSB is stored in high.

Code Listing 1-1:

MOV DWORD [Foo], 1

Test byte [Foo], 1; Test if the LSB is stored on the low side

JNZ Is_little_endian; Is the small end sequence

The above code stores 1 in 32-bit memory, by reading the low byte of memory to determine whether the 1 is stored in low-byte or high-byte, so as to distinguish between small or big-endian sequence.

On some RISC machines, you can choose between big-endian and small-order storage sequences. The big-endian format appears to be more in line with the human expression habit, while the small end-order looks less intuitive, but it has no effect on the computer's processing logic.

Experiment 1-1: Test the bit arrangement within a byte

Whether the bits in the byte have the big endian and the small end order. It seems inconclusive that we are not hardware designers and it is difficult to make judgments. I tend to think that the arrangement of bits is differentiated.

From the code listing 1-1 we can test whether the machine belongs to a small or big endian, and the principle is based on the memory sequence of bytes. Modify the code slightly to test the arrangement of bits, as shown in Listing 1-2.

Code Listing 1-2 (TOPIC01\EX1-1\BOOT.ASM):

MOV DWORD [Foo], 2;

00000000000000000000000000000010B

BT DWORD [Foo], 1; Take bit 1

SETC BL; Bit 1 is equal to 1

MOVZX ebx, BL

mov si, [message_table + ebx * 2]

Call Print_message

Next

JMP $

Foo DD 0

LSB_TO_MSB db ' byte order:lsb to MSB ', 13, 10, 0

MSB_TO_LSB db ' byte ORDER:MSB to LSB ', 13, 10, 0

Message_table DW msb_to_lsb, LSB_TO_MSB, 0

Code Listing 1-2 tests whether bit 1 in memory is the value stored in 1, and then outputs a message. Here is the test result of this experiment on a real computer.

In fact, this method may not be able to measure anything (if the CPU accesses bytes at a time, this test result does not explain anything). In this way, the byte is also ordered in small order. Data Type

In the x86/x64 system, the data of instruction processing is divided into two categories: fundamental (Basic) and numeric (numerical). The underlying types are: byte (8-bit), word (16-bit), Doubleword (32-bit), and Quadword (64-bit), which represent the width of the data that the instruction can handle at once.

Numeric data types are used in the Operation class directive, summing up that the x86/x64 system operation class instruction can handle the following four kinds of data.

①integer (integer): Includes unsigned type and singed type.

②floating-point (floating point): Includes Single-precision floating-point (single-precision floating-point number), Double-precision floating-point (double-precision floating-point number), and double Extended-precision floating-point (extended double-precision floating-point number).

③BCD (Binary-code decmial integer): Includes non-packed BCD code and PACKED-BCD code.

④SIMD (single instruction, multiple data): This is the packed type.

SIMD data is integrated with multiple integer, floating-point, or BCD data in a single operand (operand). SIMD instructions can process this data at the same time.

This article extracts from "X86x64 system exploration and programming"

Publishing Industry Publishing House

Deng Zhi

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.