Memory address: Difference between revisions
copied text from 36-bit—see that article for attribution |
→Unit of address resolution: show calculations, though a bit of an apples/oranges comparison |
||
Line 12: | Line 12: | ||
==Unit of address resolution== |
==Unit of address resolution== |
||
{{see also|Word (computer architecture)|Binary prefix#Main memory}} |
{{see also|Word (computer architecture)|Binary prefix#Main memory}} |
||
Most modern computers are ''[[byte-addressable]]'', with each address identifying a single [[octet (computing)|eight bit]] [[byte]] of storage; data too large to be stored in a single byte may reside in multiple bytes occupying a sequence of consecutive addresses. There exist ''[[word-addressable]]'' computers, where minimal addressable storage unit is exactly the processor's [[word (computer architecture)|word]]. For example, the [[Data General Nova]] [[minicomputer]], and the [[Texas Instruments TMS9900]] and [[IMP-16|National Semiconductor IMP-16]] [[microcomputer]]s used 16 bit [[word (computer architecture)|word]]s, and there were many [[36-bit]] [[mainframe computer]]s (e.g., [[PDP-10]]) which used 18-bit [[word orientation|word addressing]], not [[byte addressing]], giving an [[address space]] of 2<sup>18</sup> 36-bit words, approximately 1 megabyte of storage. The efficiency of addressing of memory depends on the bit size of the bus used for addresses – the more bits used, the more addresses are available to the computer. For example, a 8-bit-byte-addressable machine with a 20-bit address bus (e.g. [[Intel 8086]]) can address 2<sup>20</sup> (1,048,576) memory locations, or one [[mebibyte|MiB]] of memory, while a 32-bit bus (e.g. [[Intel 80386]]) addresses 2<sup>32</sup> (4,294,967,296) locations, or a 4 [[gibibyte|GiB]] [[address space]]. In contrast, a |
Most modern computers are ''[[byte-addressable]]'', with each address identifying a single [[octet (computing)|eight bit]] [[byte]] of storage; data too large to be stored in a single byte may reside in multiple bytes occupying a sequence of consecutive addresses. There exist ''[[word-addressable]]'' computers, where minimal addressable storage unit is exactly the processor's [[word (computer architecture)|word]]. For example, the [[Data General Nova]] [[minicomputer]], and the [[Texas Instruments TMS9900]] and [[IMP-16|National Semiconductor IMP-16]] [[microcomputer]]s used 16 bit [[word (computer architecture)|word]]s, and there were many [[36-bit]] [[mainframe computer]]s (e.g., [[PDP-10]]) which used 18-bit [[word orientation|word addressing]], not [[byte addressing]], giving an [[address space]] of 2<sup>18</sup> 36-bit words, approximately 1 megabyte of storage. The efficiency of addressing of memory depends on the bit size of the bus used for addresses – the more bits used, the more addresses are available to the computer. For example, a 8-bit-byte-addressable machine with a 20-bit address bus (e.g. [[Intel 8086]]) can address 2<sup>20</sup> (1,048,576) memory locations, or one [[mebibyte|MiB]] of memory, while a 32-bit bus (e.g. [[Intel 80386]]) addresses 2<sup>32</sup> (4,294,967,296) locations, or a 4 [[gibibyte|GiB]] [[address space]]. In contrast, a 36-bit word-addressable machine with an 18-bit data bus addresses only 2<sup>18</sup> (262,144) 36-bit locations (9,437,184 bits), equivalent to 1,179,648 8-bit bytes, or 1152 KB, or 1.125 [[MiB]]—slightly more than the 8086. |
||
Some older computers ([[decimal computer]]s), were ''[[decimal]] [[Numerical digit|digit]]-addressable''. For example, each address in the [[IBM 1620]]'s [[magnetic-core memory]] identified a single six bit [[binary-coded decimal]] digit, consisting of a [[parity bit]], [[flag bit]] and four numerical bits. The 1620 used 5-digit decimal addresses, so in theory the highest possible address was 99,999. In practice, the CPU supported 20,000 memory locations, and up to two optional external memory units could be added, each supporting 20,000 addresses, for a total of 60,000 (00000–59999). |
Some older computers ([[decimal computer]]s), were ''[[decimal]] [[Numerical digit|digit]]-addressable''. For example, each address in the [[IBM 1620]]'s [[magnetic-core memory]] identified a single six bit [[binary-coded decimal]] digit, consisting of a [[parity bit]], [[flag bit]] and four numerical bits. The 1620 used 5-digit decimal addresses, so in theory the highest possible address was 99,999. In practice, the CPU supported 20,000 memory locations, and up to two optional external memory units could be added, each supporting 20,000 addresses, for a total of 60,000 (00000–59999). |
Revision as of 17:49, 20 January 2012
This article needs additional citations for verification. (January 2009) |
![]() | It is requested that a diagram or diagrams be included in this article to improve its quality. Specific illustrations, plots or diagrams can be requested at the Graphic Lab. Please replace this template with a more specific media request template where possible. For more information, refer to discussion on this page and/or the listing at Wikipedia:Requested images. (January 2012) |
In computing, memory address is a data concept used at various levels by software and hardware to access the computer's primary storage memory. Memory addresses are fixed-length sequences of bits conventionally displayed and manipulated as unsigned integers. Such numerical semantic bases itself upon features of CPU (such as the instruction pointer and incremental address registers), as well upon use of the memory like an array endorsed by various programming languages.
Types of memory addresses
There are several types of memory addresses. In other words, a computer, and even one program may have several different memory address spaces.
A digital computer's memory, more specifically main memory, consists of many memory locations, each having a physical address, a code, which the CPU (or other device) can use to access it. Generally only system software, i.e. the BIOS, operating systems, and some specialized utility programs (e.g., memory testers), address physical memory using machine code operands or processor registers, instructing the CPU to direct a hardware device, called the memory controller, to use the memory bus or system bus, or separate control, address and data busses, to execute the program's commands. The memory controllers' bus consists of a number of parallel lines, each represented by a binary digit (bit). The width of the bus, and thus the number of addressable storage units, and the number of bits in each unit, varies among computers.
A computer program use memory addresses to execute machine code, store and retrieve data. Most application programs do not have indeed a knowledge about physical addresses. Rather, they address logical addresses, or virtual addresses, using computer's memory management unit and operating system memory mapping; see below.
Unit of address resolution
Most modern computers are byte-addressable, with each address identifying a single eight bit byte of storage; data too large to be stored in a single byte may reside in multiple bytes occupying a sequence of consecutive addresses. There exist word-addressable computers, where minimal addressable storage unit is exactly the processor's word. For example, the Data General Nova minicomputer, and the Texas Instruments TMS9900 and National Semiconductor IMP-16 microcomputers used 16 bit words, and there were many 36-bit mainframe computers (e.g., PDP-10) which used 18-bit word addressing, not byte addressing, giving an address space of 218 36-bit words, approximately 1 megabyte of storage. The efficiency of addressing of memory depends on the bit size of the bus used for addresses – the more bits used, the more addresses are available to the computer. For example, a 8-bit-byte-addressable machine with a 20-bit address bus (e.g. Intel 8086) can address 220 (1,048,576) memory locations, or one MiB of memory, while a 32-bit bus (e.g. Intel 80386) addresses 232 (4,294,967,296) locations, or a 4 GiB address space. In contrast, a 36-bit word-addressable machine with an 18-bit data bus addresses only 218 (262,144) 36-bit locations (9,437,184 bits), equivalent to 1,179,648 8-bit bytes, or 1152 KB, or 1.125 MiB—slightly more than the 8086.
Some older computers (decimal computers), were decimal digit-addressable. For example, each address in the IBM 1620's magnetic-core memory identified a single six bit binary-coded decimal digit, consisting of a parity bit, flag bit and four numerical bits. The 1620 used 5-digit decimal addresses, so in theory the highest possible address was 99,999. In practice, the CPU supported 20,000 memory locations, and up to two optional external memory units could be added, each supporting 20,000 addresses, for a total of 60,000 (00000–59999).
Word size versus address size
A word size is characteristic to a given computer architecture. It denotes the number of bits that a CPU can process at one time. Historically it has been sized in multiples of four and eight bits (nibbles and bytes, respectively), so sizes of 4, 8, 12, 16, 24, 32, 48, 64, and larger came into vogue with technological advances.
Very often, when referring to the word size of a modern computer, one is also describing the size of address space on that computer. For instance, a computer said to be "32-bit" also usually allows 32-bit memory addresses; a byte-addressable 32-bit computer can address bytes of memory, or 4 gibibytes (GiB). This seems logical and useful, as it allows one memory address to be efficiently stored in one word.
But this does not always hold. Computers often have memory addresses larger or smaller than their word size. For instance, almost all 8-bit processors, such as 6502, supported 16-bit addresses— if not they would have been limited to a mere 256 byte memory. The 16-bit Intel 8088 had only an 8-bit external memory bus on early IBM PCs, and the 16-bit Intel 8086 supported 20-bit addressing, allowing it to access 1 MiB rather than 64 KiBs of memory. Popular Intel Pentium processors since introduction of Physical Address Extensions (PAE) support 36-bit physical addresses, while generally having only a 32-bit word.
A modern byte-addressable 64-bit computer—with proper OS support can address bytes (or 16 exbibytes) which as of 2011[update] is considered practically unlimited.
Contents of each memory location
Each memory location in a stored-program computer holds a binary number of some sort. Its interpretation, as data of some data type or as an instruction, and use are determined by the instructions which retrieve and manipulate it.
Some early programmers combined instructions and data in words as a way to save memory, when it was expensive: The Manchester Mark 1 had space in its 40-bit words to store little bits of data – its processor ignored a small section in the middle of a word – and that was often exploited as extra data storage.[citation needed] Self-replicating programs such as viruses treat themselves sometimes as data and sometimes as instructions. Self-modifying code is generally deprecated nowadays, as it makes testing and maintenance disproportionally difficult to the saving of a few bytes, and can also give incorrect results because of the compiler or processor's assumptions about the machine's state, but is still sometimes used deliberately, with great care.
Address space in application programming
In modern multitasking environment, an application process usually has in its address space (or spaces) chunks of memory of following types:
- Machine code, including:
- program's own code (historically known as code segment or text segment);
- shared libraries.
- Data, including:
- initialized data (data segment);
- uninitialized (but allocated) variables;
- run-time stack;
- heap;
- shared memory and memory mapped files.
Some parts of address space may be not mapped at all.
Addressing schemes
A computer program can access an address given explicitly – in low-level programming this is usually called an absolute address, or sometimes a specific address, and is known as pointer data type in higher-level languages. But a program can also use relative address which specifies a location in relation to somewhere else (the base address). There are much more indirect addressing modes.
Mapping logical addresses to physical and virtual memory also adds several levels of indirection; see below.
Memory models
Many programmers prefer to address memory such that there is no distinction between code space and data space (cf. above), as well as from physical and virtual memory (see below) — in other words, numerically identical pointers refer to exactly the same byte of RAM.
However, many early computers did not support such a flat memory model — in particular, Harvard architecture machines force program storage to be completely separate from data storage. Many modern DSPs (such as the Motorola 56000) have 3 separate storage areas — program storage, coefficient storage, and data storage. Some commonly-used instructions fetch from all three areas simultaneously — fewer storage areas (even if there were the same total bytes of storage) would make those instructions run slower.
Memory models in x86 architecture
Early x86 computers used the segmented memory model addresses based on a combination of two numbers: a memory segment, and an offset within that segment. Some segments were implicitly treated as code segments, dedicated for instructions, stack segments, or normal data segments. Although the usages were different, the segments did not have different memory protections reflecting this. In the flat memory model all segments (segment registers) are generally set to zero, and only offsets are variable.
Virtual memory versus physical memory
![]() | The topic of this article may not meet Wikipedia's general notability guideline. (February 2011) |
Virtual memory is now universally used on desktop machines. It maps physical memory to different addresses using page tables. By doing so the operating system can decide to allocate memory as it deems most efficient without causing the program to halt from a long garbage collection process. Some literature [citation needed] suggests that, on the whole, garbage collection is the most efficient of memory reclamation strategies [dubious – discuss], but it is not ideal if it cuts in to 'tidy up' memory just as the program is controlling the firing of a missile or a landing on the moon, because it is non-deterministic.
The physical blocks of memory (typically[citation needed] 4 KB chunks) are mapped to virtual addresses by a virtual memory program in the kernel, and supported by the processor hardware, though it was formerly done all in software. The purpose of virtual memory is to abstract memory allocation, allowing the physical space to be allocated as best for the hardware (that is, usually in good sized blocks), and to still be seen as contiguous from a program or compiler's perspective. Virtual memory is supported by some operating systems (for example Linux and Windows but not MS-DOS). One may think of virtual memory as a filter, or an alternate set of memory addresses that allow programs to read from memory as quickly as possible without requiring it to be at a particular place. Programs use these contiguous virtual addresses, rather than real, and often fragmented, physical addresses, to store instructions and data. When the program is actually executed, the virtual addresses are translated by the processor[dubious – discuss] into real memory addresses. logical address is a synonym[citation needed] for virtual address.
Virtual memory also effectively allows the address space to be larger than – or rather, extend beyond – the amount of real (or physical) memory available; the computer can put rarely-accessed pages into secondary storage (similar, at a level, in behavior to CPU cache) and use the real memory (RAM) for new or active tasks. So the virtual address space might contain, say, twice as many addresses as main memory with the extra addresses mapped to hard disk space in the form of a swap file (used in Linux) or page file (the default on Windows XP and later MS operating systems). When required they are copied back (called swapping) into main memory as soon as they are needed. These movements are performed, typically, as a background process – and in that sense are transparent to programs. However, if due care is not taken, this can often lead to thrashing.
See also
- Memory model (programming)
- Memory allocation
- Memory address register
- Base address
- Offset (computer science), also known as a displacement
- Endianness
- Memory management unit (MMU)
- Page table
- Memory protection
- Memory segmentation
- Low-level programming language