Introduction to Linux
◾
27
such as an adder,
a multiplier, a shifter, and a comparator. The CPU also contains data reg-
isters. These are temporary storage locations used in the CPU to store partial computations
as the CPU executes program code.
As a simple example, if the current program requires performing the operation
A
=
B * (C
+
D), then C and D are loaded from memory into registers. They are then added
together and the result stored in a register. B is loaded from
memory and stored in a reg-
ister. The values of B and C
+
D are then multiplied and the result is stored in a register.
Finally, the result is moved from register to memory. This instruction requires the use of
the adder, multiplier, and some registers.
Aside from the data registers, the CPU has control registers. These are used by the con-
trol unit portion of the CPU to handle the fetch-execute cycle. There are several important
control registers to note. The program counter register (PC) stores
the location in memory
of the next instruction to fetch. The instruction register (IR) stores the instruction cur-
rently being executed. The status flags (SF) are individual bits stored in a single register to
store information about the last operation such as whether it resulted in a positive, nega-
tive, or zero value, whether it produced a carry, and whether it caused an interrupt. The
stack pointer (SP) points to the location in memory corresponding to the top of the run-
time stack. Different processors may have other control registers.
Every computer also has one or more forms of memory. Types
of memory include regis-
ters, cache, main memory, and secondary storage. Registers are built into the CPU. Cache is
fast memory that allows the CPU to access data and program code without delay. However,
cache is expensive and so a limited amount is made available. Often today, computers have
several caches, some on the CPU and some separated off the CPU (known as on-chip and
off-chip cache, respectively). The on-chip caches provide faster access than off-chip caches
because
of their location, but must be smaller in size because of the limited space available
on the CPU.
Main memory, often called DRAM, is a good deal slower than cache but is far cheaper.
While a computer might have 8 GB of DRAM, it will probably only have 1–2 MB of cache
(if you are unfamiliar with storage capacity terminology, see the appendix).
You might ask why we need main memory when cache is so much faster. Think of
DRAM as an extension to cache. That is, we prefer to keep as much of our running pro-
grams
and data in cache memories, but because of their limited size, we extend memory by
placing the rest in DRAM. Alternatively, you can think of cache as being a special area to
place the items that are most useful so that the CPU can look there first in hopes of avoid-
ing access to DRAM.
Even with the large DRAM sizes of our modern computers,
DRAM cannot usually store
all of the program code that users are executing. For instance, some GUI programs are
dozens of GBytes in size by themselves whereas DRAM might be limited to just 8 GByte.
So we need a back-up to DRAM. For this, we use the hard disk in two forms. First, tem-
porary hard disk storage that backs up DRAM is called
Do'stlaringiz bilan baham: