This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:multiasm:papc:chapter_6_4 [2024/09/27 20:34] – created pczekalski | en:multiasm:papc:chapter_6_4 [2025/05/18 19:02] (current) – [Pointers] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Data types, data encoding | + | ====== Data Types and Encoding ====== |
| + | ===== Fundamental data types ===== | ||
| + | Fundamental data types cover the types of data elements that are stored in memory as 8-bit (Byte), 16-bit (Word), 32-bit (Doubleword), | ||
| + | |||
| + | <figure fundamentaldata> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The data types which can be used in the x64 architecture processors can be integers or floating point numbers. Integers are processed by the main CPU as single values (scalars). They can also be packed into vectors and processed with the specific SIMD instructions, | ||
| + | |||
| + | ===== Integers | ||
| + | Integers are the numbers without the fractional part. In x64 architecture, | ||
| + | |||
| + | ===== Integer scalar data types ===== | ||
| + | Integer data types can be one, two, four or eight bytes in length. Unsigned integers are binary encoded in natural binary code. It means that the starting value is 0 (zero), and the maximum value is formed with bits " | ||
| + | <table uinttypes> | ||
| + | < | ||
| + | ^ Name ^ Number of bits ^ Minimum value ^ Maximum value ^ Minimum value (hex) ^ Maximum value (hex) ^ | ||
| + | | Byte | 8 | 0 | 255 | 0x00 | 0xFF | | ||
| + | | Word | 16 | 0 | 65535 | 0x0000 | ||
| + | | Doubleword | ||
| + | | Quadword | ||
| + | </ | ||
| + | |||
| + | Signed integers are binary encoded in 2's complement binary code. The highest bit of the value is a sign bit. If it is zero, the number is non-negative; | ||
| + | <table sinttypes> | ||
| + | < | ||
| + | ^ Name ^ Number of bits ^ Minimum value ^ Maximum value ^ Minimum value (hex) ^ Maximum value (hex) ^ | ||
| + | | Signed Byte | 8 | -128 | 127 | 0x80 | 0x7F | | ||
| + | | Signed Word | 16 | -32768 | ||
| + | | Signed Doubleword | ||
| + | | Signed Quadword | ||
| + | </ | ||
| + | ===== Integer vector data types ===== | ||
| + | Vector data types were introduced with SIMD instructions starting with the MMX extension, and followed in the SSE and AVX extensions. They form the packed data types containing multiple elements of the same size. The elements can be considered as signed or unsigned depending on the algorithm and instructions used. | ||
| + | |||
| + | The 64-bit packed integer data type contains eight Bytes, four Words or two Doublewords as shown in figure {{ref> | ||
| + | |||
| + | <figure packedint64> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The 128-bit packed integer data type contains sixteen Bytes, eight Words, four Doublewords or two Quadwords as shown in figure {{ref> | ||
| + | |||
| + | <figure packedint128> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The 256-bit packed integer data type contains thirty-two Bytes, sixteen Words, eight Doublewords, | ||
| + | |||
| + | <figure packedint256> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The 512-bit packed integer data type contains sixty-four Bytes, thirty-two Words, sixteen Doublewords, | ||
| + | |||
| + | <figure packedint512> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Floating point values ===== | ||
| + | Floating point values store the data encoded for calculation on real numbers. Depending on the precision required for the algorithm, we can use different data sizes. Scalar data types are supported by the FPU (Floating Point Unit), offering single precision, double precision or double extended precision real numbers. In C/C++ compilers, they are referred to as float, double and long double data types, respectively. Vector (packed) floating-point data types can be processed by many SSE and AVX instructions, | ||
| + | |||
| + | <figure floattypes> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <table tablefloattypes> | ||
| + | < | ||
| + | ^ Name ^ Bits ^ Mantissa bits ^ Exponent bits ^ Min value ^ Max value ^ | ||
| + | | Double extended | ||
| + | | Double precision | ||
| + | | Single precision | ||
| + | | Half precision | ||
| + | | Brain Float | 16 | 7 | 8 | {{: | ||
| + | </ | ||
| + | |||
| + | ===== Floating point vector data types ===== | ||
| + | Floating point vectors are formed with single or double precision packed data formats. They are processed by SSE or AVX instructions in a SIMD approach of processing. A 128-bit packed data format can store four single-precision data elements or two double-precision data elements. A 256-bit packed data format can store eight single-precision values or four double-precision values. A 512-bit packed data format can store sixteen single-precision values or eight double-precision values. These packed data types are shown in figure {{ref> | ||
| + | It is worth mentioning that some instructions operate on a single floating-point value, using only the lowest elements of the operands. | ||
| + | |||
| + | <figure packedfloattypes> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | ===== Bit field data type ===== | ||
| + | A bit field is a data type whose size is counted by the number of bits it occupies. The bit field can start at any bit position in the fundamental data type and can be up to 32 bits long. MASM supports it with the RECORD data type. The bit field type is shown in figure {{ref> | ||
| + | |||
| + | <figure bitfieldtype> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Pointers ===== | ||
| + | Pointers store the address of the memory which contains interesting information. They can point to the data or the instruction. If the segmentation is enabled, pointers can be near or far. The far pointer contains the logical address (formed with the segment and offset parts). The near pointer contains the offset only. The offset can be 16, 32 or 64 bits long. The segment selector is always stored as a 16-bit number. Illustration of possible pointer types is shown in figure {{ref> | ||
| + | |||
| + | <figure pointertypes> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | The offset is often the result of complex addressing mode calculations and is called an effective address. | ||
| + | </ | ||