Word data type length

In computing, a word is the natural unit of data used by a particular processor design. A word is a fixed-sized datum handled as a unit by the instruction set or the hardware of the processor. The number of bits or digits[a] in a word (the word size, word width, or word length) is an important characteristic of any specific processor design or computer architecture.

The size of a word is reflected in many aspects of a computer’s structure and operation; the majority of the registers in a processor are usually word-sized and the largest datum that can be transferred to and from the working memory in a single operation is a word in many (not all) architectures. The largest possible address size, used to designate a location in memory, is typically a hardware word (here, «hardware word» means the full-sized natural word of the processor, as opposed to any other definition used).

Documentation for older computers with fixed word size commonly states memory sizes in words rather than bytes or characters. The documentation sometimes uses metric prefixes correctly, sometimes with rounding, e.g., 65 kilowords (KW) meaning for 65536 words, and sometimes uses them incorrectly, with kilowords (KW) meaning 1024 words (210) and megawords (MW) meaning 1,048,576 words (220). With standardization on 8-bit bytes and byte addressability, stating memory sizes in bytes, kilobytes, and megabytes with powers of 1024 rather than 1000 has become the norm, although there is some use of the IEC binary prefixes.

Several of the earliest computers (and a few modern as well) use binary-coded decimal rather than plain binary, typically having a word size of 10 or 12 decimal digits, and some early decimal computers have no fixed word length at all. Early binary systems tended to use word lengths that were some multiple of 6-bits, with the 36-bit word being especially common on mainframe computers. The introduction of ASCII led to the move to systems with word lengths that were a multiple of 8-bits, with 16-bit machines being popular in the 1970s before the move to modern processors with 32 or 64 bits.[1] Special-purpose designs like digital signal processors, may have any word length from 4 to 80 bits.[1]

The size of a word can sometimes differ from the expected due to backward compatibility with earlier computers. If multiple compatible variations or a family of processors share a common architecture and instruction set but differ in their word sizes, their documentation and software may become notationally complex to accommodate the difference (see Size families below).

Uses of wordsEdit

Depending on how a computer is organized, word-size units may be used for:

Fixed-point numbers
Holders for fixed point, usually integer, numerical values may be available in one or in several different sizes, but one of the sizes available will almost always be the word. The other sizes, if any, are likely to be multiples or fractions of the word size. The smaller sizes are normally used only for efficient use of memory; when loaded into the processor, their values usually go into a larger, word sized holder.
Floating-point numbers
Holders for floating-point numerical values are typically either a word or a multiple of a word.
Addresses
Holders for memory addresses must be of a size capable of expressing the needed range of values but not be excessively large, so often the size used is the word though it can also be a multiple or fraction of the word size.
Registers
Processor registers are designed with a size appropriate for the type of data they hold, e.g. integers, floating-point numbers, or addresses. Many computer architectures use general-purpose registers that are capable of storing data in multiple representations.
Memory–processor transfer
When the processor reads from the memory subsystem into a register or writes a register’s value to memory, the amount of data transferred is often a word. Historically, this amount of bits which could be transferred in one cycle was also called a catena in some environments (such as the Bull GAMMA 60 [fr]).[2][3] In simple memory subsystems, the word is transferred over the memory data bus, which typically has a width of a word or half-word. In memory subsystems that use caches, the word-sized transfer is the one between the processor and the first level of cache; at lower levels of the memory hierarchy larger transfers (which are a multiple of the word size) are normally used.
Unit of address resolution
In a given architecture, successive address values designate successive units of memory; this unit is the unit of address resolution. In most computers, the unit is either a character (e.g. a byte) or a word. (A few computers have used bit resolution.) If the unit is a word, then a larger amount of memory can be accessed using an address of a given size at the cost of added complexity to access individual characters. On the other hand, if the unit is a byte, then individual characters can be addressed (i.e. selected during the memory operation).
Instructions
Machine instructions are normally the size of the architecture’s word, such as in RISC architectures, or a multiple of the «char» size that is a fraction of it. This is a natural choice since instructions and data usually share the same memory subsystem. In Harvard architectures the word sizes of instructions and data need not be related, as instructions and data are stored in different memories; for example, the processor in the 1ESS electronic telephone switch has 37-bit instructions and 23-bit data words.

Word size choiceEdit

When a computer architecture is designed, the choice of a word size is of substantial importance. There are design considerations which encourage particular bit-group sizes for particular uses (e.g. for addresses), and these considerations point to different sizes for different uses. However, considerations of economy in design strongly push for one size, or a very few sizes related by multiples or fractions (submultiples) to a primary size. That preferred size becomes the word size of the architecture.

Character size was in the past (pre-variable-sized character encoding) one of the influences on unit of address resolution and the choice of word size. Before the mid-1960s, characters were most often stored in six bits; this allowed no more than 64 characters, so the alphabet was limited to upper case. Since it is efficient in time and space to have the word size be a multiple of the character size, word sizes in this period were usually multiples of 6 bits (in binary machines). A common choice then was the 36-bit word, which is also a good size for the numeric properties of a floating point format.

After the introduction of the IBM System/360 design, which uses eight-bit characters and supports lower-case letters, the standard size of a character (or more accurately, a byte) becomes eight bits. Word sizes thereafter are naturally multiples of eight bits, with 16, 32, and 64 bits being commonly used.

Variable-word architecturesEdit

Early machine designs included some that used what is often termed a variable word length. In this type of organization, an operand has no fixed length. Depending on the machine and the instruction, the length might be denoted by a count field, by a delimiting character, or by an additional bit called, e.g., flag, or word mark. Such machines often use binary-coded decimal in 4-bit digits, or in 6-bit characters, for numbers. This class of machines includes the IBM 702, IBM 705, IBM 7080, IBM 7010, UNIVAC 1050, IBM 1401, IBM 1620, and RCA 301.

Most of these machines work on one unit of memory at a time and since each instruction or datum is several units long, each instruction takes several cycles just to access memory. These machines are often quite slow because of this. For example, instruction fetches on an IBM 1620 Model I take 8 cycles (160 μs) just to read the 12 digits of the instruction (the Model II reduced this to 6 cycles, or 4 cycles if the instruction did not need both address fields). Instruction execution takes a variable number of cycles, depending on the size of the operands.

Word, bit and byte addressingEdit

The memory model of an architecture is strongly influenced by the word size. In particular, the resolution of a memory address, that is, the smallest unit that can be designated by an address, has often been chosen to be the word. In this approach, the word-addressable machine approach, address values which differ by one designate adjacent memory words. This is natural in machines which deal almost always in word (or multiple-word) units, and has the advantage of allowing instructions to use minimally sized fields to contain addresses, which can permit a smaller instruction size or a larger variety of instructions.

When byte processing is to be a significant part of the workload, it is usually more advantageous to use the byte, rather than the word, as the unit of address resolution. Address values which differ by one designate adjacent bytes in memory. This allows an arbitrary character within a character string to be addressed straightforwardly. A word can still be addressed, but the address to be used requires a few more bits than the word-resolution alternative. The word size needs to be an integer multiple of the character size in this organization. This addressing approach was used in the IBM 360, and has been the most common approach in machines designed since then.

When the workload involves processing fields of different sizes, it can be advantageous to address to the bit. Machines with bit addressing may have some instructions that use a programmer-defined byte size and other instructions that operate on fixed data sizes. As an example, on the IBM 7030[4] («Stretch»), a floating point instruction can only address words while an integer arithmetic instruction can specify a field length of 1-64 bits, a byte size of 1-8 bits and an accumulator offset of 0-127 bits.

In a byte-addressable machine with storage-to-storage (SS) instructions, there are typically move instructions to copy one or multiple bytes from one arbitrary location to another. In a byte-oriented (byte-addressable) machine without SS instructions, moving a single byte from one arbitrary location to another is typically:

  1. LOAD the source byte
  2. STORE the result back in the target byte

Individual bytes can be accessed on a word-oriented machine in one of two ways. Bytes can be manipulated by a combination of shift and mask operations in registers. Moving a single byte from one arbitrary location to another may require the equivalent of the following:

  1. LOAD the word containing the source byte
  2. SHIFT the source word to align the desired byte to the correct position in the target word
  3. AND the source word with a mask to zero out all but the desired bits
  4. LOAD the word containing the target byte
  5. AND the target word with a mask to zero out the target byte
  6. OR the registers containing the source and target words to insert the source byte
  7. STORE the result back in the target location

Alternatively many word-oriented machines implement byte operations with instructions using special byte pointers in registers or memory. For example, the PDP-10 byte pointer contained the size of the byte in bits (allowing different-sized bytes to be accessed), the bit position of the byte within the word, and the word address of the data. Instructions could automatically adjust the pointer to the next byte on, for example, load and deposit (store) operations.

Powers of twoEdit

Different amounts of memory are used to store data values with different degrees of precision. The commonly used sizes are usually a power of two multiple of the unit of address resolution (byte or word). Converting the index of an item in an array into the memory address offset of the item then requires only a shift operation rather than a multiplication. In some cases this relationship can also avoid the use of division operations. As a result, most modern computer designs have word sizes (and other operand sizes) that are a power of two times the size of a byte.

Size familiesEdit

As computer designs have grown more complex, the central importance of a single word size to an architecture has decreased. Although more capable hardware can use a wider variety of sizes of data, market forces exert pressure to maintain backward compatibility while extending processor capability. As a result, what might have been the central word size in a fresh design has to coexist as an alternative size to the original word size in a backward compatible design. The original word size remains available in future designs, forming the basis of a size family.

In the mid-1970s, DEC designed the VAX to be a 32-bit successor of the 16-bit PDP-11. They used word for a 16-bit quantity, while longword referred to a 32-bit quantity; this terminology is the same as the terminology used for the PDP-11. This was in contrast to earlier machines, where the natural unit of addressing memory would be called a word, while a quantity that is one half a word would be called a halfword. In fitting with this scheme, a VAX quadword is 64 bits. They continued this 16-bit word/32-bit longword/64-bit quadword terminology with the 64-bit Alpha.

Another example is the x86 family, of which processors of three different word lengths (16-bit, later 32- and 64-bit) have been released, while word continues to designate a 16-bit quantity. As software is routinely ported from one word-length to the next, some APIs and documentation define or refer to an older (and thus shorter) word-length than the full word length on the CPU that software may be compiled for. Also, similar to how bytes are used for small numbers in many programs, a shorter word (16 or 32 bits) may be used in contexts where the range of a wider word is not needed (especially where this can save considerable stack space or cache memory space). For example, Microsoft’s Windows API maintains the programming language definition of WORD as 16 bits, despite the fact that the API may be used on a 32- or 64-bit x86 processor, where the standard word size would be 32 or 64 bits, respectively. Data structures containing such different sized words refer to them as:

  • WORD (16 bits/2 bytes)
  • DWORD (32 bits/4 bytes)
  • QWORD (64 bits/8 bytes)

A similar phenomenon has developed in Intel’s x86 assembly language – because of the support for various sizes (and backward compatibility) in the instruction set, some instruction mnemonics carry «d» or «q» identifiers denoting «double-«, «quad-» or «double-quad-«, which are in terms of the architecture’s original 16-bit word size.

An example with a different word size is the IBM System/360 family. In the System/360 architecture, System/370 architecture and System/390 architecture, there are 8-bit bytes, 16-bit halfwords, 32-bit words and 64-bit doublewords. The z/Architecture, which is the 64-bit member of that architecture family, continues to refer to 16-bit halfwords, 32-bit words, and 64-bit doublewords, and additionally features 128-bit quadwords.

In general, new processors must use the same data word lengths and virtual address widths as an older processor to have binary compatibility with that older processor.

Often carefully written source code – written with source-code compatibility and software portability in mind – can be recompiled to run on a variety of processors, even ones with different data word lengths or different address widths or both.

Table of word sizesEdit

key: bit: bits, c: characters, d: decimal digits, w: word size of architecture, n: variable size, wm: Word mark
Year Computer
architecture
Word size w Integer
sizes
Floating­point
sizes
Instruction
sizes
Unit of address
resolution
Char size
1837 Babbage
Analytical engine
50 d w Five different cards were used for different functions, exact size of cards not known. w
1941 Zuse Z3 22 bit w 8 bit w
1942 ABC 50 bit w
1944 Harvard Mark I 23 d w 24 bit
1946
(1948)
{1953}
ENIAC
(w/Panel #16[5])
{w/Panel #26[6]}
10 d w, 2w
(w)
{w}

(2 d, 4 d, 6 d, 8 d)
{2 d, 4 d, 6 d, 8 d}


{w}
1948 Manchester Baby 32 bit w w w
1951 UNIVAC I 12 d w 12w w 1 d
1952 IAS machine 40 bit w 12w w 5 bit
1952 Fast Universal Digital Computer M-2 34 bit w? w 34 bit = 4-bit opcode plus 3×10 bit address 10 bit
1952 IBM 701 36 bit 12w, w 12w 12w, w 6 bit
1952 UNIVAC 60 n d 1 d, … 10 d 2 d, 3 d
1952 ARRA I 30 bit w w w 5 bit
1953 IBM 702 n c 0 c, … 511 c 5 c c 6 bit
1953 UNIVAC 120 n d 1 d, … 10 d 2 d, 3 d
1953 ARRA II 30 bit w 2w 12w w 5 bit
1954
(1955)
IBM 650
(w/IBM 653)
10 d w
(w)
w w 2 d
1954 IBM 704 36 bit w w w w 6 bit
1954 IBM 705 n c 0 c, … 255 c 5 c c 6 bit
1954 IBM NORC 16 d w w, 2w w w
1956 IBM 305 n d 1 d, … 100 d 10 d d 1 d
1956 ARMAC 34 bit w w 12w w 5 bit, 6 bit
1956 LGP-30 31 bit w 16 bit w 6 bit
1957 Autonetics Recomp I 40 bit w, 79 bit, 8 d, 15 d 12w 12w, w 5 bit
1958 UNIVAC II 12 d w 12w w 1 d
1958 SAGE 32 bit 12w w w 6 bit
1958 Autonetics Recomp II 40 bit w, 79 bit, 8 d, 15 d 2w 12w 12w, w 5 bit
1958 Setun 6 trit (~9.5 bits)[b] up to 6 tryte up to 3 trytes 4 trit?
1958 Electrologica X1 27 bit w 2w w w 5 bit, 6 bit
1959 IBM 1401 n c 1 c, … 1 c, 2 c, 4 c, 5 c, 7 c, 8 c c 6 bit + wm
1959
(TBD)
IBM 1620 n d 2 d, …
(4 d, … 102 d)
12 d d 2 d
1960 LARC 12 d w, 2w w, 2w w w 2 d
1960 CDC 1604 48 bit w w 12w w 6 bit
1960 IBM 1410 n c 1 c, … 1 c, 2 c, 6 c, 7 c, 11 c, 12 c c 6 bit + wm
1960 IBM 7070 10 d[c] w, 1-9 d w w w, d 2 d
1960 PDP-1 18 bit w w w 6 bit
1960 Elliott 803 39 bit
1961 IBM 7030
(Stretch)
64 bit 1 bit, … 64 bit,
1 d, … 16 d
w 12w, w bit (integer),
12w (branch),
w (float)
1 bit, … 8 bit
1961 IBM 7080 n c 0 c, … 255 c 5 c c 6 bit
1962 GE-6xx 36 bit w, 2 w w, 2 w, 80 bit w w 6 bit, 9 bit
1962 UNIVAC III 25 bit w, 2w, 3w, 4w, 6 d, 12 d w w 6 bit
1962 Autonetics D-17B
Minuteman I Guidance Computer
27 bit 11 bit, 24 bit 24 bit w
1962 UNIVAC 1107 36 bit 16w, 13w, 12w, w w w w 6 bit
1962 IBM 7010 n c 1 c, … 1 c, 2 c, 6 c, 7 c, 11 c, 12 c c 6 b + wm
1962 IBM 7094 36 bit w w, 2w w w 6 bit
1962 SDS 9 Series 24 bit w 2w w w
1963
(1966)
Apollo Guidance Computer 15 bit w w, 2w w
1963 Saturn Launch Vehicle Digital Computer 26 bit w 13 bit w
1964/1966 PDP-6/PDP-10 36 bit w w, 2 w w w 6 bit
7 bit (typical)
9 bit
1964 Titan 48 bit w w w w w
1964 CDC 6600 60 bit w w 14w, 12w w 6 bit
1964 Autonetics D-37C
Minuteman II Guidance Computer
27 bit 11 bit, 24 bit 24 bit w 4 bit, 5 bit
1965 Gemini Guidance Computer 39 bit 26 bit 13 bit 13 bit, 26 —bit
1965 IBM 1130 16 bit w, 2w 2w, 3w w, 2w w 8 bit
1965 IBM System/360 32 bit 12w, w,
1 d, … 16 d
w, 2w 12w, w, 112w 8 bit 8 bit
1965 UNIVAC 1108 36 bit 16w, 14w, 13w, 12w, w, 2w w, 2w w w 6 bit, 9 bit
1965 PDP-8 12 bit w w w 8 bit
1965 Electrologica X8 27 bit w 2w w w 6 bit, 7 bit
1966 SDS Sigma 7 32 bit 12w, w w, 2w w 8 bit 8 bit
1969 Four-Phase Systems AL1 8 bit w ? ? ?
1970 MP944 20 bit w ? ? ?
1970 PDP-11 16 bit w 2w, 4w w, 2w, 3w 8 bit 8 bit
1971 CDC STAR-100 64 bit 12w, w 12w, w 12w, w bit 8 bit
1971 TMS1802NC 4 bit w ? ?
1971 Intel 4004 4 bit w, d 2w, 4w w
1972 Intel 8008 8 bit w, 2 d w, 2w, 3w w 8 bit
1972 Calcomp 900 9 bit w w, 2w w 8 bit
1974 Intel 8080 8 bit w, 2w, 2 d w, 2w, 3w w 8 bit
1975 ILLIAC IV 64 bit w w, 12w w w
1975 Motorola 6800 8 bit w, 2 d w, 2w, 3w w 8 bit
1975 MOS Tech. 6501
MOS Tech. 6502
8 bit w, 2 d w, 2w, 3w w 8 bit
1976 Cray-1 64 bit 24 bit, w w 14w, 12w w 8 bit
1976 Zilog Z80 8 bit w, 2w, 2 d w, 2w, 3w, 4w, 5w w 8 bit
1978
(1980)
16-bit x86 (Intel 8086)
(w/floating point: Intel 8087)
16 bit 12w, w, 2 d
(2w, 4w, 5w, 17 d)
12w, w, … 7w 8 bit 8 bit
1978 VAX 32 bit 14w, 12w, w, 1 d, … 31 d, 1 bit, … 32 bit w, 2w 14w, … 1414w 8 bit 8 bit
1979
(1984)
Motorola 68000 series
(w/floating point)
32 bit 14w, 12w, w, 2 d
(w, 2w, 212w)
12w, w, … 712w 8 bit 8 bit
1985 IA-32 (Intel 80386) (w/floating point) 32 bit 14w, 12w, w
(w, 2w, 80 bit)
8 bit, … 120 bit
14w … 334w
8 bit 8 bit
1985 ARMv1 32 bit 14w, w w 8 bit 8 bit
1985 MIPS I 32 bit 14w, 12w, w w, 2w w 8 bit 8 bit
1991 Cray C90 64 bit 32 bit, w w 14w, 12w, 48 bit w 8 bit
1992 Alpha 64 bit 8 bit, 14w, 12w, w 12w, w 12w 8 bit 8 bit
1992 PowerPC 32 bit 14w, 12w, w w, 2w w 8 bit 8 bit
1996 ARMv4
(w/Thumb)
32 bit 14w, 12w, w w
(12w, w)
8 bit 8 bit
2000 IBM z/Architecture
(w/vector facility)
64 bit 14w, 12w, w
1 d, … 31 d
12w, w, 2w 14w, 12w, 34w 8 bit 8 bit, UTF-16, UTF-32
2001 IA-64 64 bit 8 bit, 14w, 12w, w 12w, w 41 bit (in 128-bit bundles)[7] 8 bit 8 bit
2001 ARMv6
(w/VFP)
32 bit 8 bit, 12w, w
(w, 2w)
12w, w 8 bit 8 bit
2003 x86-64 64 bit 8 bit, 14w, 12w, w 12w, w, 80 bit 8 bit, … 120 bit 8 bit 8 bit
2013 ARMv8-A and ARMv9-A 64 bit 8 bit, 14w, 12w, w 12w, w 12w 8 bit 8 bit
Year Computer
architecture
Word size w Integer
sizes
Floating­point
sizes
Instruction
sizes
Unit of address
resolution
Char size
key: bit: bits, d: decimal digits, w: word size of architecture, n: variable size

[8][9]

See alsoEdit

  • Integer (computer science)

NotesEdit

  1. ^ Many early computers were decimal, and a few were ternary
  2. ^ The bit equivalent is computed by taking the amount of information entropy provided by the trit, which is  . This gives an equivalent of about 9.51 bits for 6 trits.
  3. ^ Three-state sign

ReferencesEdit

  1. ^ a b Beebe, Nelson H. F. (2017-08-22). «Chapter I. Integer arithmetic». The Mathematical-Function Computation Handbook — Programming Using the MathCW Portable Software Library (1 ed.). Salt Lake City, UT, USA: Springer International Publishing AG. p. 970. doi:10.1007/978-3-319-64110-2. ISBN 978-3-319-64109-6. LCCN 2017947446. S2CID 30244721.
  2. ^ Dreyfus, Phillippe (1958-05-08) [1958-05-06]. Written at Los Angeles, California, USA. System design of the Gamma 60 (PDF). Western Joint Computer Conference: Contrasts in Computers. ACM, New York, NY, USA. pp. 130–133. IRE-ACM-AIEE ’58 (Western). Archived (PDF) from the original on 2017-04-03. Retrieved 2017-04-03. […] Internal data code is used: Quantitative (numerical) data are coded in a 4-bit decimal code; qualitative (alpha-numerical) data are coded in a 6-bit alphanumerical code. The internal instruction code means that the instructions are coded in straight binary code.
    As to the internal information length, the information quantum is called a «catena,» and it is composed of 24 bits representing either 6 decimal digits, or 4 alphanumerical characters. This quantum must contain a multiple of 4 and 6 bits to represent a whole number of decimal or alphanumeric characters. Twenty-four bits was found to be a good compromise between the minimum 12 bits, which would lead to a too-low transfer flow from a parallel readout core memory, and 36 bits or more, which was judged as too large an information quantum. The catena is to be considered as the equivalent of a character in variable word length machines, but it cannot be called so, as it may contain several characters. It is transferred in series to and from the main memory.
    Not wanting to call a «quantum» a word, or a set of characters a letter, (a word is a word, and a quantum is something else), a new word was made, and it was called a «catena.» It is an English word and exists in Webster’s although it does not in French. Webster’s definition of the word catena is, «a connected series;» therefore, a 24-bit information item. The word catena will be used hereafter.
    The internal code, therefore, has been defined. Now what are the external data codes? These depend primarily upon the information handling device involved. The Gamma 60 [fr] is designed to handle information relevant to any binary coded structure. Thus an 80-column punched card is considered as a 960-bit information item; 12 rows multiplied by 80 columns equals 960 possible punches; is stored as an exact image in 960 magnetic cores of the main memory with 2 card columns occupying one catena. […]
  3. ^ Blaauw, Gerrit Anne; Brooks, Jr., Frederick Phillips; Buchholz, Werner (1962). «4: Natural Data Units» (PDF). In Buchholz, Werner (ed.). Planning a Computer System – Project Stretch. McGraw-Hill Book Company, Inc. / The Maple Press Company, York, PA. pp. 39–40. LCCN 61-10466. Archived (PDF) from the original on 2017-04-03. Retrieved 2017-04-03. […] Terms used here to describe the structure imposed by the machine design, in addition to bit, are listed below.
    Byte denotes a group of bits used to encode a character, or the number of bits transmitted in parallel to and from input-output units. A term other than character is used here because a given character may be represented in different applications by more than one code, and different codes may use different numbers of bits (i.e., different byte sizes). In input-output transmission the grouping of bits may be completely arbitrary and have no relation to actual characters. (The term is coined from bite, but respelled to avoid accidental mutation to bit.)
    A word consists of the number of data bits transmitted in parallel from or to memory in one memory cycle. Word size is thus defined as a structural property of the memory. (The term catena was coined for this purpose by the designers of the Bull GAMMA 60 [fr] computer.)
    Block refers to the number of words transmitted to or from an input-output unit in response to a single input-output instruction. Block size is a structural property of an input-output unit; it may have been fixed by the design or left to be varied by the program. […]
  4. ^ «Format» (PDF). Reference Manual 7030 Data Processing System (PDF). IBM. August 1961. pp. 50–57. Retrieved 2021-12-15.
  5. ^ Clippinger, Richard F. [in German] (1948-09-29). «A Logical Coding System Applied to the ENIAC (Electronic Numerical Integrator and Computer)». Aberdeen Proving Ground, Maryland, US: Ballistic Research Laboratories. Report No. 673; Project No. TB3-0007 of the Research and Development Division, Ordnance Department. Retrieved 2017-04-05.{{cite web}}: CS1 maint: url-status (link)
  6. ^ Clippinger, Richard F. [in German] (1948-09-29). «A Logical Coding System Applied to the ENIAC». Aberdeen Proving Ground, Maryland, US: Ballistic Research Laboratories. Section VIII: Modified ENIAC. Retrieved 2017-04-05.{{cite web}}: CS1 maint: url-status (link)
  7. ^ «4. Instruction Formats» (PDF). Intel Itanium Architecture Software Developer’s Manual. Vol. 3: Intel Itanium Instruction Set Reference. p. 3:293. Retrieved 2022-04-25. Three instructions are grouped together into 128-bit sized and aligned containers called bundles. Each bundle contains three 41-bit instruction slots and a 5-bit template field.
  8. ^ Blaauw, Gerrit Anne; Brooks, Jr., Frederick Phillips (1997). Computer Architecture: Concepts and Evolution (1 ed.). Addison-Wesley. ISBN 0-201-10557-8. (1213 pages) (NB. This is a single-volume edition. This work was also available in a two-volume version.)
  9. ^ Ralston, Anthony; Reilly, Edwin D. (1993). Encyclopedia of Computer Science (3rd ed.). Van Nostrand Reinhold. ISBN 0-442-27679-6.

Word Size and Data Types

A word is the amount of data that a machine can process at one time. This fits into the document analogy that includes characters (usually eight bits) and pages (many words, often 4 or 8KB worth) as other measurements of data. A word is an integer number of bytes for example, one, two, four, or eight. When someone talks about the «n-bits» of a machine, they are generally talking about the machine’s word size. For example, when people say the Pentium is a 32-bit chip, they are referring to its word size, which is 32 bits, or four bytes.

The size of a processor’s general-purpose registers (GPR’s) is equal to its word size. The widths of the components in a given architecture for example, the memory bus are usually at least as wide as the word size. Typically, at least in the architectures that Linux supports, the memory address space is equal to the word size[2]. Consequently, the size of a pointer is equal to the word size. Additionally, the size of the C type long is equal to the word size, whereas the size of the int type is sometimes less than that of the word size. For example, the Alpha has a 64-bit word size. Consequently, registers, pointers, and the long type are 64 bits in length. The int type, however, is 32 bits long. The Alpha can access and manipulate 64 bits, one word at a time.

Further read : http://www.makelinux.com/books/lkd2/ch19lev1sec2

One of the first things that is going to strike many first-time programmers of the Win32 API is that there are tons and tons of old data types to deal with. Sometimes, just keeping all the correct data types in order can be more difficult than writing a nice program. This page will talk a little bit about some of the data types that a programmer will come in contact with.

Hungarian Notation[edit | edit source]

First, let’s make a quick note about the naming convention used for some data types, and some variables. The Win32 API uses the so-called «Hungarian Notation» for naming variables. Hungarian Notation requires that a variable be prefixed with an abbreviation of its data type, so that when you are reading the code, you know exactly what type of variable it is. The reason this practice is done in the Win32 API is because there are many different data types, making it difficult to keep them all straight. Also, there are a number of different data types that are essentially defined the same way, and therefore some compilers will not pick up on errors when they are used incorrectly. As we discuss each data type, we will also note the common prefixes for that data type.

Putting the letter «P» in front of a data type, or «p» in front of a variable usually indicates that the variable is a pointer. The letters «LP» or the prefix «lp» stands for «Long Pointer», which is exactly the same as a regular pointer on 32 bit machines. LP data objects are simply legacy objects that were carried over from Windows 3.1 or earlier, when pointers and long pointers needed to be differentiated. On modern 32-bit systems, these prefixes can be used interchangeably.

LPVOID[edit | edit source]

LPVOID data types are defined as being a «pointer to a void object». This may seem strange to some people, but the ANSI-C standard allows for generic pointers to be defined as «void*» types. This means that LPVOID pointers can be used to point to any type of object, without creating a compiler error. However, the burden is on the programmer to keep track of what type of object is being pointed to.

Also, some Win32 API functions may have arguments labeled as «LPVOID lpReserved». These reserved data members should never be used in your program, because they either depend on functionality that hasn’t yet been implemented by Microsoft, or else they are only used in certain applications. If you see a function with an «LPVOID lpReserved» argument, you must always pass a NULL value for that parameter — some functions will fail if you do not do so.

LPVOID objects frequently do not have prefixes, although it is relatively common to prefix an LPVOID variable with the letter «p», as it is a pointer.

DWORD, WORD, BYTE[edit | edit source]

These data types are defined to be a specific length, regardless of the target platform. There is a certain amount of additional complexity in the header files to achieve this, but the result is code that is very well standardized, and very portable to different hardware platforms and different compilers.

DWORDs (Double WORDs), the most commonly occurring of these data types, are defined always to be unsigned 32-bit quantities. On any machine, be it 16, 32, or 64 bits, a DWORD is always 32 bits long. Because of this strict definition, DWORDS are very common and popular on 32-bit machines, but are less common on 16-bit and 64-bit machines.

WORDs (Single WORDs) are defined strictly as unsigned 16-bit values, regardless of what machine you are programming on. BYTEs are defined strictly as being unsigned 8-bit values. QWORDs (Quad WORDs), although rare, are defined as being unsigned 64-bit quantities. Putting a «P» in front of any of these identifiers indicates that the variable is a pointer. putting two «P»s in front indicates it’s a pointer to a pointer. These variables may be unprefixed, or they may use any of the prefixes common with DWORDs. Because of the differences in compilers, the definition of these data types may be different, but typically these definitions are used:

#include <stdint.h>
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;

Notice that these definitions are not the same in all compilers. It is a known issue that the GNU GCC compiler uses the long and short specifiers differently from the Microsoft C Compiler. For this reason, the windows header files typically will use conditional declarations for these data types, depending on the compiler being used. In this way, code can be more portable.

As usual, we can define pointers to these types as:

#include <stdint.h>
typedef uint8_t * PBYTE;
typedef uint16_t * PWORD;
typedef uint32_t * PDWORD;
typedef uint64_t * PQWORD;
typedef uint8_t ** PPBYTE;
typedef uint16_t ** PPWORD;
typedef uint32_t ** PPDWORD;
typedef uint64_t ** PPQWORD;

DWORD variables are typically prefixed with «dw». Likewise, we have the following prefixes:

Data Type Prefix
BYTE «b»
WORD «w»
DWORD «dw»
QWORD «qw»

LONG, INT, SHORT, CHAR[edit | edit source]

These types are not defined to a specific length. It is left to the host machine to determine exactly how many bits each of these types has.

Types
typedef long LONG;
typedef unsigned long ULONG;
typedef int INT;
typedef unsigned int UINT;
typedef short SHORT;
typedef unsigned short USHORT;
typedef char CHAR;
typedef unsigned char UCHAR;
LONG notation
LONG variables are typically prefixed with an «l» (lower-case L).
UINT notation
UINT variables are typically prefixed with an «i» or a «ui» to indicate that it is an integer, and that it is unsigned.
CHAR, UCHAR notation
These variables are usually prefixed with a «c» or a «uc» respectively.

If the size of the variable doesn’t matter, you can use some of these integer types. However, if you want to exactly specify the size of a variable, so that it has a certain number of bits, use the BYTE, WORD, DWORD, or QWORD identifiers, because their lengths are platform-independent and never change.

STR, LPSTR[edit | edit source]

STR data types are string data types, with storage already allocated. This data type is less common than the LPSTR. STR data types are used when the string is supposed to be treated as an immediate array, and not as a simple character pointer. The variable name prefix for a STR data type is «sz» because it’s a zero-terminated string (ends with a null character).

Most programmers will not define a variable as a STR, opting instead to define it as a character array, because defining it as an array allows the size of the array to be set explicitly. Also, creating a large string on the stack can cause greatly undesirable stack-overflow problems.

LPSTR stands for «Long Pointer to a STR», and is essentially defined as such:

#define STR * LPSTR;

LPSTR can be used exactly like other string objects, except that LPSTR is explicitly defined as being ASCII, not unicode, and this definition will hold on all platforms. LPSTR variables will usually be prefixed with the letters «lpsz» to denote a «Long Pointer to a String that is Zero-terminated». The «sz» part of the prefix is important, because some strings in the Windows world (especially when talking about the DDK) are not zero-terminated. LPSTR data types, and variables prefixed with the «lpsz» prefix can all be used seamlessly with the standard library <string.h> functions.

TCHAR[edit | edit source]

TCHAR data types, as will be explained in the section on Unicode, are generic character data types. TCHAR can hold either standard 1-byte ASCII characters, or wide 2-byte Unicode characters. Because this data type is defined by a macro and is not set in stone, only character data should be used with this type. TCHAR is defined in a manner similar to the following (although it may be different for different compilers):

#ifdef UNICODE
#define TCHAR WORD
#else
#define TCHAR BYTE
#endif

TSTR, LPTSTR[edit | edit source]

Strings of TCHARs are typically referred to as TSTR data types. More commonly, they are defined as LPTSTR types as such:

#define TCHAR * LPTSTR

These strings can be either UNICODE or ASCII, depending on the status of the UNICODE macro. LPTSTR data types are long pointers to generic strings, and may contain either ASCII strings or Unicode strings, depending on the environment being used. LPTSTR data types are also prefixed with the letters «lpsz».

HANDLE[edit | edit source]

HANDLE data types are some of the most important data objects in Win32 programming, and also some of the hardest for new programmers to understand. Inside the kernel, Windows maintains a table of all the different objects that the kernel is responsible for. Windows, buttons, icons, mouse pointers, menus, and so on, all get an entry in the table, and each entry is assigned a unique address known as a HANDLE. If you want to pick a particular entry out of that table, you need to give Windows the HANDLE value, and Windows will return the corresponding table entry.

HANDLEs are defined as void pointers (void*). They are used as unique identifiers to each Windows object in our program such as a button, a window an icon, etc. Specifically their definition follows:
typedef PVOID HANDLE;
and
typedef void *PVOID;
In other words HANDLE = void*.

HANDLEs are generally prefixed with an «h». Handles are unsigned integers that Windows uses internally to keep track of objects in memory. Windows moves objects like memory blocks in memory to make room, if the object is moved in memory, the handles table is updated.

Below are a few special handles that are worth discussing:

HWND[edit | edit source]

HWND data types are «Handles to a Window», and are used to keep track of the various objects that appear on the screen. To communicate with a particular window, you need to have a copy of the window’s handle. HWND variables are usually prefixed with the letters «hwnd», just so the programmer knows they are important.

Canonically, main windows are defined as:

HWND hwnd;

Child windows are defined as:

HWND hwndChild1, hwndChild2...

and Dialog Box handles are defined as:

HWND hDlg;

Although you are free to name these variables whatever you want in your own program, readability and compatibility suffer when an idiosyncratic naming scheme is chosen — or worse, no scheme at all.

HINSTANCE[edit | edit source]

HINSTANCE variables are handles to a program instance. Each program gets a single instance variable, and this is important so that the kernel can communicate with the program. If you want to create a new window, for instance, you need to pass your program’s HINSTANCE variable to the kernel, so that the kernel knows what program instance the new window belongs to. If you want to communicate with another program, it is frequently very useful to have a copy of that program’s instance handle. HINSTANCE variables are usually prefixed with an «h», and furthermore, since there is frequently only one HINSTANCE variable in a program, it is canonical to declare that variable as such:

HINSTANCE hInstance;

It is usually a benefit to make this HINSTANCE variable a global value, so that all your functions can access it when needed.

[edit | edit source]

If your program has a drop-down menu available (as most visual Windows programs do), that menu will have an HMENU handle associated with it. To display the menu, or to alter its contents, you need to have access to this HMENU handle. HMENU handles are frequently prefixed with simply an «h».

WPARAM, LPARAM[edit | edit source]

In the earlier days of Microsoft Windows, parameters were passed to a window in one of two formats: WORD-length (16-bit) parameters, and LONG-length (32-bit) parameters. These parameter types were defined as being WPARAM (16-bit) and LPARAM (32-bit). However, in modern 32-bit systems, WPARAM and LPARAM are both 32 bits long. The names however have not changed, for legacy reasons.

WPARAM and LPARAM variables are generic function parameters, and are frequently type-cast to other data types including pointers and DWORDs.

Next Chapter[edit | edit source]

  • Unicode
  1. 07-02-2010


    #1

    karuna is offline


    Registered User


    Question what is the WORD datatype?

    I had a programming class assignment to make a simple guessing game ( we’re just starting out programming in C) and I read this code that changes the color of the console:

    Code:

    HANDLE mainwin = GetStdHandle ( STD_OUTPUT_HANDLE );
        WORD DefaultColor; 
        CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
        GetConsoleScreenBufferInfo(mainwin, &csbiInfo); 
        DefaultColor = csbiInfo.wAttributes;

    I know what each bit does, but I would like to know what the WORD datatype / structure is? ( sorry if I’m not using the correct terminology, I’m just beginning programming, and it’s really fun )

    Thanks alot for the help


  2. 07-02-2010


    #2

    Elysia is offline


    C++まいる!Cをこわせ!


    WORD in a Windows environment is just that — a word. Now the definition of a word is some type of data that is 16 bits (2 bytes) for x86. Typically an alias for short (ONLY guaranteed under Windows!).

    Quote Originally Posted by Adak
    View Post

    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

    Quote Originally Posted by Salem
    View Post

    You mean it’s included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.


  3. 07-02-2010


    #3

    karuna is offline


    Registered User


    Oh ok, thanks
    So word is sort of like a string that can only hold to characters? (2 bytes?)
    Thanks for the help


  4. 07-03-2010


    #4

    DeadPlanet is offline


    Registered User


    No, a WORD is just a 2-Byte (unsigned) data type, you can use it for whatever you like.

    Windows Data Types (Windows)


  5. 07-03-2010


    #5

    Elysia is offline


    C++まいる!Cをこわせ!


    When we speak of types such as word, dword, qword, etc, they all refer to a storage unit, or place, where we can store at most n bytes (2, 4, 8 in this case respectively). What exactly you want to store in them is up to you, because to the hardware it’s all bits.
    Now, these types are all (usually) represented by integer types (short, int, long long respectively in this case).

    Quote Originally Posted by Adak
    View Post

    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

    Quote Originally Posted by Salem
    View Post

    You mean it’s included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.


  6. 07-03-2010


    #6

    karuna is offline


    Registered User


    Oh ok, its starting to make more sense now,
    Thanks alot Elysia and DeadPlanet,
    + the link was really helpful as well


  7. 07-05-2010


    #7

    GReaper is offline


    Programming Wraith

    GReaper's Avatar


    Short question: Why are data types bigger that BYTE called *WORD? (WORD, DWORD, QWORD … )

    Devoted my life to programming…


  8. 07-05-2010


    #8

    bernt is offline


    Just a pushpin.

    bernt's Avatar


    Short question: Why are data types bigger that BYTE called *WORD? (WORD, DWORD, QWORD … )

    A word is the data size that a processor naturally handles. So for a 32-bit processor, it’s theoretically 32 bits (or an int), although x86 processors support 16 and 32 bits equally via the *x and e*x registers.

    Since smaller data sizes have to be padded for operations there’s really no speed gain from using e.g. bytes vs. words. So it’s probably more convenient to define data types that are word size rather than byte size — that way you have a much larger int range at no cost of speed.
    Therefore Windows has DWORD (double word) and QWORD (quad word), which correspond to 2 words and 4 words respectively (or a 16-bit long int and long long int).

    Since the modern Windows API really came about in Windows ’95 and that was a 16-bit system, WORD was defined to be a 16-bit data structure (on 16-bit processors, an int, and a short was 8 bits like a char). Hence the 16-bit Windows word. And it stuck on into win32, probably for compatibility reasons.

    EDIT: Nevermind the ’95 part, 16-bit started out with DOS, but the point is still valid.

    Last edited by bernt; 07-06-2010 at 08:23 AM.

    Consider this post signed


  9. 07-05-2010


    #9

    GReaper is offline


    Programming Wraith

    GReaper's Avatar


    Devoted my life to programming…





български (bg)


Deutsch (de)
English (en)

español (es)


français (fr)



日本語 (ja)
한국어 (ko)





русский (ru)






中文(中国大陆)‎ (zh_CN)


1D — Variables and Data Types (author: Tao Yue, state: changed)

Variables are similar to constants, but their values can be changed as the program runs. Variables must first be declared in Pascal before they can be used:

var
  IdentifierList1 : DataType1;
  IdentifierList2 : DataType2;
  IdentifierList3 : DataType3;
  ...

IdentifierList is a series of identifiers, separated by commas (,). All identifiers in the list are declared as being of the same data type.

The basic data field data types in Pascal include:

  • Integer
  • Word
  • LongInt
  • Real
  • Char
  • Boolean

Standard Pascal does not make provision for the string data type, but most modern compilers do. Experienced Pascal programmers also use pointers for dynamic memory allocation, objects for object-oriented programming, and many others, but this gets you started.

More information on Pascal data types:

  • The Integer data type can contain whole numbers. the size of an integer depends on the compiler and the processor. On PCs before the 80386, «integer» meant 16-bit whole numbers in the range from -32768 to 32767. This is the signed range that can be stored in a 16-bit word, and is a legacy of the era when 16-bit CPUs were common. For backward compatibility purposes, a 32-bit signed integer is a longint and can hold a much greater range of values, 2147483647 to -2147483648.
  • The Word data type is a 16-bit unsigned integer, which has a range of 0 to 65535.
  • The Real data type has a range from 3.4×10-38 to 3.4×1038, in addition to the same range on the negative side. Real values are stored inside the computer similarly to scientific notation, with a mantissa and exponent, with some complications. In Pascal, you can express real values in your code in either fixed-point notation or in scientific notation, with the character E separating the mantissa from the exponent. Thus, 452.13 is the same as 4.5213e2
  • The Char data type holds characters. Be sure to enclose them in single quotes, like so: ‘a’ ‘B’ ‘+’ Standard Pascal uses 8-bit characters, not 16-bits, so Unicode, which is used to represent all the world’s language sets in one UNIfied CODE system, is not supported.
  • The WideChar is a two-byte character (an element of a DBCS: Double Byte Character Set) and can hold a Unicode character. Note: some Unicode characters require two WideChars. See UTF-16.
  • Free Pascal supports the Delphi implementation of the PChar data type. PChar is defined as a pointer to a Char type, but allows additional operations. The PChar type can be understood best as the Pascal equivalent of a C-style null-terminated string, i.e. a variable of type PChar is a pointer that points to an array of type Char, which is ended by a null-character (#0). Free Pascal supports initializing of PChar typed constants, or a direct assignment. For example, the following pieces of code are equivalent:
program one;  
var P : PChar;  
begin  
  P := 'This is a null-terminated string.';  
  WriteLn (P);  
end.
program two;  
const P : PChar = 'This is a null-terminated string.';  
begin  
  WriteLn (P);  
end.
  • Free Pascal supports the String type as it is defined in Turbo Pascal: a sequence of characters with an optional size specification. It also supports AnsiStrings (with unlimited length) as in Delphi. And can be declared as:
variable_name : string;                    // if no length is given, it defaults to 255
variable_name : string[length];            // where:  1 < length <= 255
  • The predefined type ShortString is defined as a string of size 255.
  • AnsiStrings are strings that have no length limit. They are reference counted and are guaranteed to be null terminated. Internally, an ansistring is treated as a pointer: the actual content of the string is stored on the heap, as much memory as needed to store the string content is allocated.
  • WideStrings (used to represent unicode character strings) are implemented in much the same way as ansistrings: reference counted, null-terminated arrays, only they are implemented as arrays of WideChars instead of regular Chars.
  • The Boolean data type can have only two values: TRUE and FALSE

An example of declaring several variables is:

var
  Age, Year, Grade : integer;
  Circumference : real;
  LetterGrade : char;
  DidYouFail : boolean;

From the FPC manual

integer types

Type Range Bytes
Byte 0 .. 255 1
Shortint -128 .. 127 1
Smallint -32768 .. 32767 2
Word 0 .. 65535 2
Integer smallint or longint 2 or 4
Cardinal longword 4
Longint -2147483648 .. 2147483647 4
Longword 0..4294967295 4
Int64 -9223372036854775808 .. 9223372036854775807 8
QWord 0 .. 18446744073709551615 8

Free Pascal does automatic type conversion in expressions where different kinds of integer types are used.

real types

Type Range Significant digits Bytes
Real platform dependent ??? 4 or 8
Single 1.5E-45 .. 3.4E38 7-8 4
Double 5.0E-324 .. 1.7E308 15-16 8
Extended* 1.9E-4932 .. 1.1E4932 19-20 10
Comp -2E64+1 .. 2E63-1 19-20 8
Currency -922337203685477.5808 922337203685477.5807 8
  • Note that for Windows 64 bits and non-Intel targets Extended is an alias for Double.
boolean types

Type Bytes Ord(True)
Boolean 1 1
ByteBool 1 Any nonzero value
WordBool 2 Any nonzero value
LongBool 4 Any nonzero value

Понравилась статья? Поделить с друзьями:
  • Word dasturini ishga tushirish
  • Word dasturida uztransliterator dot lotin kril dasturi
  • Word dasturida rasmlar bilan ishlash
  • Word dasturida ramka hosil qilish
  • Word dasturida lotin krill