【深入理解计算机系统】 二:计算机中的内存

3.1. RAM Memory

In this document you will learn how the RAM in a computer system is used to store all the data and coded required to execute a program. You will also learn about a technique called indirection used to manipulate memory addresses as if they were data.

Unless otherwise stated, for all the examples in this document we will assume that the memory cell contains 8 bits (1 byte).


igital circuits can only process information represented as zeros and ones, but in order to do that, data must be stored and remembered in another circuit. In a computer system, this storage location is called the RAM (random access memory), or memory in general. This memory is simply a large table of cells, each of them capable of storing a pre-defined unit of information such as, for example one byte.

As in the case of any other table, you need to know two numbers: the size of each of its elements, and the number of elements it has. Nowadays, memories used in computer systems store information in multiples of bytes, and the most common memory cell size is 1 byte. A memory can be seen then as a table containing a large number of bytes. The cells in this table are numbered started with the number zero for the first cell, one for the second, two for the third, and so on. The number of a cell is called its memory address and when written, it is usually prefixed by the symbol “@”. All the address values of a memory

is usually called its address space. The following figure shows the structure, content and addresses of a RAM chip storing S bytes.

Structure of RAM memory

The way data is accessed in memory is determined by the size of its cells. For example, if the cells store one byte each, the data is accessed one byte at a time. Some computer systems are capable of accessing a set of contiguous cells in one single operation, but this is simply to optimize the access time. Still, each cell is referred by its unique address. So, if you want to change the value of a single bit in a byte of a memory storing one byte per cell, you still need to read the entire byte, modify the single bit, and write the byte back again to memory.

Internally, each memory cell is implemented using a set of transistors and gates that are capable of remembering a previously defined set of bits. A memory chip is then simply a collection of cells, each of them capable of storing a unit of information, and each of them with a unique address. RAM memory also has the property of being volatile, that is, when the power is turned off, the data is lost. Non-volatile memories are those that maintain the information even after the system has been powered down. A USB memory stick, or a hard drive are examples of non-volatile memory. There are two types of volatile memory: static and dynamic.

Static RAM (also known as SRAM) is the memory that works intuitively as described. Data is stored in a cell until it is overwritten or the power is stopped. The number of transistors required to implement one cell is around one hundred, and the time it takes for the chip to perform a read operations is around ten nanoseconds (one nanosecond is 10-9 second).

Dynamic RAM (also known as DRAM) supports the same operations (read and write) and is also organised in cells, each of which has an address. The main difference is that the physical structure of the cell is much simpler and the value is stored using capacitors. If one of these capacitors is charged it is storing a one, and if discharged it is storing a zero. The problem is that capacitors leak current, and therefore, those that are charged (and therefore storing a one) start to discharge over certain time interval. If no operation is done, even if the chip has power, the charge in the capacitors disappears and the cell loses its value. However, if a read operation is done over a cell, it refreshes the charges of those capacitors storing ones. Cells take a few milliseconds to lose their charge.

This type of cell may seem to be useless because it forgets its data, however it is actually used in most computers. The reason is that the cells are much simpler than those in static memory and therefore chips with higher capacity (number of bytes) are more easily produced. The counterpart is that each memory cell must be read after certain time interval, thus slowing down the overall read/write operations. This problem is alleviated by including (in the chip itself) a mechanism to refresh the cells by simply reading all of them continuously before the capacitors lose their charge. This is the reason why this memory is called dynamic - because it is constantly being read or refreshed. Most computer systems use dynamic memory as their main memory due to its low cost and high capacity. The size of a cell in a dynamic memory is approximately one fourth of a static cell, and it is much simpler to design and produce.

Static RAM has a clear advantage over dynamic RAM - it is faster. Computer systems tend to use both types of memory. For components that need to be extremely fast, SRAM is used. For those components where a large amount of memory is needed, DRAM is the solution.

3.2. Memory operations

The two operations allowed in memory are reading a value and writing a value. In a read operation, the memory receives an address and returns the content of the cell with that address. In the write operation, the memory receives an address and a value (of the size of a cell), writes the value in the cell with the given address, and no result is produced. Another way to specify the behaviour of these operations is by using the notation typically used in programming languages when defining a function. For example, for a memory with 1 byte cells:

Byte Read(Address a): Given an address, returns the byte stored in that cell. void Write(Address a, Byte b): Store byte b in the cell with address a.


The data stored initially in memory before any read or write operation is executed is undefined. If the first operation executed in RAM memory after starting a computer system is a read operation, the result is undefined or garbage. Thus, every read operation must be performed on a cell in which content has been previously written. The next figure shows the effect of executing a sequence of six operations over in a given memory.

Memory operations

As memories are digital circuits, all the data must be encoded in base 2, and this also includes the data needed for the read and write operations. The data that is read or written is a byte (if the memory cell has 1 byte size) and is encoded in base 2. The addresses are unsigned integers that may have values from zero to the number of cells minus one. These addresses need to be encoded also in base 2.

Therefore, reading one address from memory consists of sending the memory chip a set of bits encoding a memory address, and the memory chip sends the set of bits stored in the referred cell. Analogously, a write operation consists of sending two sets of bits, one encoding the information to be stored in the cell, and the other set encoding the address of the cell to be written.

The encoding of memory address has a direct relation with the size of the memory. Every cell in memory has an address, and therefore, the number of cells corresponds to the maximum value allowed for an address plus one (given that addresses begin at 0). Since the addresses are encoded in base 2, a memory chip with addresses represented by n bits, cannot have more than 

LaTeX: 2^n
 cells numbered from 0 to 
LaTeX: 2^n-1
. Another way to state this relation is that the size 
LaTeX: S
 of a memory chip and the number of bits 
LaTeX: n
 used to encode the addresses must satisfy the following equation:

LaTeX: S\le2^n

As a consequence of this relationship between the number of bits used to encode an address and the number of elements, it is often the case that the number of cells in a memory chip is a power of two. Once a number of bits are used to encode the address, chips tend to include as many cells as possible.

The size of a memory chip is measured in units that do not follow the conventional rules of multiples of 10. Instead, the units are related by multiples of powers of 2. A kilobyte is 1024 bytes. The different units and their relation is shown in the following table:

Prefix Symbol Size (Power)
kilo K
LaTeX: 2^{10}
mega M
LaTeX: 2^{20}
giga G
LaTeX: 2^{30}
tera T
LaTeX: 2^{40}
peta P
LaTeX: 2^{50}
exa E
LaTeX: 2^{60}
zetta Z
LaTeX: 2^{70}
yotta Y
LaTeX: 2^{80}

3.3. Connection between mem

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值