Skip to main content

Part 1 - Prelude to Assembly Language

Assembly language: what it is, why it is studied, and where it is used.

Computer Architecture and Assembly Language

Assembly language is used to write programs in terms of the basic operations of a processor. This is a tutorial in the assembly language for the MIPS32 processor chip. This tutorial uses the SPIM simulator of the chip rather than actual hardware.

The architecture of a computer is a logical description of its components and its basic operations. In pure assembly language one assembly language statement corresponds to one basic operation of the processor. When a programmer writes in assembly language the programmer is asking for the basic operations of the processor. The architecture of the processor is visible in every statement of the program.

Pure assembly language is rare. Most application programs are written in a high level language. Even when assembly language is used it usually has been enhanced. Features are added to it to make it more programmer-friendly. This extended assembly language includes statements that correspond to several basic machine operations. The MIPS extended assembly language does this, but the processor chip is still visible.

Programs in high level languages such as C or Pascal are (mostly) independent of the processor they run on. Programs in Java are totally independent of the processor. But in assembly language the program is written totally in terms of the processor. This chapter starts our a tour of assembly language.

Chapter Topics:

  • The Basic Computer Cycle
  • Machine Instructions
  • Machine Language
  • Assembly Language
  • Language Translation
  • Emulation
  • Object Modules and Load Modules
  • Separate Assembly
Question 1

Do all processor chips have the same architecture?

Answer

No. Each family of processor chip (MIPS, PIC, SPARC, Alpha, Motorola, Intel, et al.) has its own architecture.

Different processor architectures

The architecture of a processor chip is a description of its basic components and of its basic operations.

Each processor family has its own architecture. Assembly language is a programming view of the architecture of a particular processor. Each type of processor has its own assembly language.

When you study an assembly language, you study the architecture of a particular processor. The study of any assembly language increases your professional understanding of computers. These notes are about the MIPS processor, which is a nice processor to study. The concepts in MIPS assembly are universal.

These notes discuss assembly language from a computer science perspective. They explain what is going on in a computer system at the assembly language level. This is a view that is above the electronic view of computer architecture, but is below the operating systems view of the computer system. Computer scientists understand computers at many levels. They understand how the many levels are built one on top of another. Each of these levels corresponds to one or more courses in a computer science degree program.

Question 2

Does your understanding of computers depend on which assembly language you study?

Answer

No. A well-designed modern assembly language is best, but any one is OK.

Fundamentals

The MIPS architecture is modern and well-designed. The MIPS chip was designed from the ground up in 1985. Its design includes the best ideas of computer architecture. It may surprise you that something done in 1985 could be called "modern". However, the fundamentals of any science change slowly, if at all. The MIPS is an excellent chip to study if you want to learn the fundamentals of how computers work.

An assembly language program describes exactly what the hardware should do, step by step, in terms of the basic operations of the hardware. In a high level programming language like C or Java a programmer is mostly unaware of computer architecture. The same source program can run (after compiling) on any processor family.

These notes are about fundamental assembly-level computer architecture. To do this effectively it is necessary to actually learn the assembly language and details of a particular processor, and to write programs for it. This is somewhat like those experiments you did in high school chemistry. Their goal was to teach you the fundamentals of chemistry, not to teach you how to make test tubes full of colorful water. But without the colorful experiments your understanding of chemistry might remain abstract and vague, and would soon be forgotten.

Question 3

Do you need to learn how to drive a car each time you buy a new one?

Answer

No, although different car models differ in many ways, all cars are fundamentally the same. You don't need special lessons if you switch from a Ford to a Chevy.

Assembly language is much the same way. The details vary from processor to processor, but the fundamentals are the same.

Basic machine cycle

Most processors endlessly repeat three basic steps. Each machine cycle results in the execution of one machine instruction. A modern processor performs millions of machine cycles per second.

A machine instruction is a pattern of bits that corresponds to a fundamental operation of the processor such as adding two 32-bit integers together or testing if a value is zero. The details of the machine cycle differ between processor families. The machine cycle of most processor chips looks like the following:

  • Fetch the Instruction. The instruction is fetched from memory. The program counter (PC) is part of the processor. It contains the address of the instruction in memory.
  • Increment the Program Counter. The program counter now points to the next instruction.
  • Execute the Instruction. The operation asked for by the current machine instruction is performed.

On a 32-bit processor, memory addresses are 32 bits wide and so the program counter (PC) holds a 32 bit address.

Question 4

In what order are machine instructions executed by the basic machine cycle?

Answer

In sequential order, one after another.

Machine instructions

Instructions are normally executed in sequence. The program counter advances forward through memory one instruction at a time. Each time an instruction is executed, the next one is automatically selected for the next execution cycle.

Operations like "add two integers" and "compare two integers" are operations that a processor does in one machine cycle. Loops and branches require machine instructions that alter the normal sequence.

A machine instruction is a pattern of bits that directs the processor to perform one machine operation. Here is the machine instruction that directs the MIPS processor to add two 32-bit registers together (a register is a part of the processor that holds a bit pattern).

0000 0001 0010 1011 1000 0000 0010 0000

The instruction is 32 bits long. Each bit is 0 or 1. When bit patterns are displayed in a book they are usually shown in groups of four (as here). Of course, the spaces between groups are a convention of printing and are not actually part of the bit pattern.

Some of the bits in the instruction specify the operation (adding two registers), other bits specify which two registers to add. A few more bits say where to put the result.

Question 5

Inspect the instruction. Is it clear what the bits of the instruction mean?

Answer

No.

Assembly language statement

The layout of a machine instruction is part of the architecture of a processor chip. Without knowing the layout you can't tell what the instruction means. Even if you know the layout, it is hard to remember what the patterns mean and hard to write machine instructions.

A statement in pure assembly language corresponds to one machine instruction. Assembly language is much easier to write than machine language. Here is the previous machine instruction and the assembly language that it corresponds to:

machine instruction                             assembly language statement

0000 0001 0010 1011 1000 0000 0010 0000 add $t0,$t1,$t2

The instruction means: add the integers in registers $t1 and $t2 and put the result in register $t0. To create the machine instruction from the assembly language statement a translation program called an assembler is used.

Humans find assembly language much easier to use than machine language for many reasons.

  • It is hard for humans to keep track of those ones and zeros.
  • By using symbols programmers gain flexibility in describing the computation.
  • Assembly language is a compact notation.

Enhanced assembly language includes additional convenience features. It has instructions (called pseudoinstructions) that correspond to several machine instructions.

Question 6

Once you know assembly language, is it hard to write an assembly language statement?

Answer

No.

Program translation

The assembly language statement says the same thing as the machine language instruction, but must be translated into a bit pattern before it can be executed. An assembly language program consists of assembly language statements, statements that define data, and some additional information that helps in the translation. Here is a fragment of an assembly language program and its translation into bit patterns.

machine instructions                             assembly statements

0011 0100 0000 0001 0000 0000 0000 1001 ori $1, $0, 9
0000 0000 0100 0001 0000 0000 0001 1000 mult $2, $1
0000 0000 0000 0000 0100 0000 0001 0010 mflo $8
0011 0100 0000 0001 0000 0000 0000 1001 ori $1, $0, 5
0000 0000 0100 0000 0000 0000 0100 1000 div $8, $1

Years ago, to run a program written in FORTRAN you used a compiler to translate the program into assembly language. Then you used an assembler to translate the assembly language into machine language. Finally, you loaded the machine language into the computer's memory and executed your program.

Modern compilers usually translate a source program directly into machine language which is contained in a file called an object module (more on this later). But for now let us think about translating FORTRAN into assembly language.

FORTRAN is a high level language. It is intended to run on all types of computers regardless of architecture. FORTRAN statements can be written without knowing the architecture of the computer, and can be run on any computer (after translation).

Question 7

Do you think that languages such as COBOL, C, and Pascal are translated like FORTRAN?

Answer

Yes.

Several translations

All programming languages other than machine language must be translated into machine language before they can be executed. A high level language is independent of architecture. It requires a specific translator (compiler) for each architecture. The more modern the language, the more distant the source code is from the machine language. FORTRAN is 50 years old and is closer to machine language than modern languages. Here is a statement in FORTRAN:

result = 6*alpha+beta

Here is a translation of that statement into MIPS assembly language:

lw  $t0,alpha           # copy alpha to register $t0
lw $t1,beta # copy beta to register $t1
mul $t2,$t0,6 # multiply $t0 times 6; result in $t2
add $t2,$t2,$t1 # add $t2 and $t1; result in $t2
sw $t2,result # copy answer to result

Here is a translation of that statement into Digital Equipment Corporation VAX assembly language:

MULL3   #6,ALPHA,R5
ADDL3 R5,BETA,RESULT
Question 8

Is the architecture of the VAX similar to that of MIPS?

Answer

No. The two machines are very different.

Machine language

There is not just one language called "assembly language." Each processor family (such as Intel, VAX, MIPS, Alpha, ...) has its own machine instructions and a corresponding assembly language. MIPS assembly language is only for MIPS processors. The VAX assembly language is only for VAX processors. There is a different assembly language for IBM mainframe computers, and others for Intel-based PCs.

All processors follow the same basic machine cycle. (See above.) The differences between processors are in the details of what operations are done in the "execute" phase of the basic machine cycle.

Assembly language describes computations in terms of the hardware of a particular processor. A high level computer programming language (ideally) describes computations in terms of the problem being solved. Since there are many types of problems, there are many high level languages, each designed for particular types of problems. For example, object-oriented languages describe computations in terms of the objects of the problem and operations with them.

It is much easier to program a computer in a high level language than in assembly language, especially when the programming language matches the problem. There will never be a universal programming language since no one language is best for all problems.

Question 9

(Hard thought question:) What type of problem is assembly language best suited for?

Answer

Problems that involve the very computer the program is running on.

Main storage

Assembly language does match the problem when the problem is the operation of the computer system. Assembly language is used for operating systems, compilers, communications, low-level graphics, and other programs where the architecture of the processor must be visible. Often with these programs the crucial parts are written in assembly and the rest in a high level language (usually C). The most common use of assembly language is in programming embedded systems. Here a processor chip is part of a machine built for a specific purpose. Examples are aviation electronics, communication satellites, DVD players, robots, automobile electronics, cell phones, and game consoles. MIPS chips are commonly used in these (and for this reason more MIPS chips are made each year than any other processor).

Now let us move on to the memory of a computer system. Eight bits make up a byte. A bit is a single on/off value. Early computers had rows of toggle switches which were used to set the values of bits in main memory. You could program these computers by entering the bits of each machine instruction from the front panel switches. A light above each switch showed whether it was on or off (1 or 0). Modern computers have more convenient methods for moving bit patterns into memory.

The bytes that make up the machine instructions of a program are stored in main memory and fetched into the processor as needed. Data is also kept in main memory. Keeping both data and instructions in main memory is one of the characteristics of a Von Neumann machine, the name for the basic design of most modern computers.

In the MIPS, as in most computers, each byte of main memory has an address. An address is an integer that uniquely identifies the byte. The addresses run from 0 up to about four billion. However, on the MIPS, user programs and data (such as you will write) are restricted to the first two billion addresses.

Question 10

Is it necessary to install four billion bytes of RAM on a MIPS computer? (Hint: the address range of a MIPS is the same as that of a 32-bit Pentium).

Answer

No. Both processors have the same range of logical addresses, but there need not be actual RAM behind each address.

Architecture vs. implementation

The architecture of a computer is a logical description of its components and its basic operations.

The MIPS family of computers all have the same assembly-level architecture. This means that all MIPS machines can be programmed using the same assembly language. The actual electronics that implement the architecture may differ greatly between versions of the chip. This is analogous to "car architecture". Two Jaguars may appear the same to a driver (same styling, same user controls, same operation) but have different components under the hood. The architecture is the same, but the implementation (and performance) is different. Keep this in mind as you visit the used car lots in Silicon Valley.

The architecture of a MIPS is different from the architecture of a Pentium. Both are Von Neumann machines, so they look the same in general, but the details of operation are completely different. They have different machine languages, and hence different assembly languages.

Question 11

(Hard Thought Question:) Must a machine language program be run on an actual processor chip (i.e., on hardware)? Hint: Think about Java.

Answer

No. Sometimes machine instructions (such as Java .class files) are interpreted by software.

Emulation

Apple computers can run Microsoft Windows ".exe" files (executable files) intended for Intel computers even though these machines have different architectures. This is done by running a program on the Apple that emulates (imitates) an Intel processor.

A processor's architecture is a logical description of its components and its basic operations. This says nothing about how the architecture is implemented. The operations need not be done in electronics. They can be done with software. A program that implements a processor's architecture is the logical equivalent of an implementation in silicon. Such a program is called an emulator. Any computer can run an emulator of any kind of computer. Of course, somebody has to write the emulator, and that is difficult.

The basic flow chart of an emulator program is the machine cycle of the emulated processor. But now the steps are implemented in software, not in silicon. The emulated machine cycle involves perhaps thousands of program statements. When the emulator is running, each simulated machine cycle requires the execution of many instructions on the host processor. So emulators run much slower than the processor they are emulating.

This course uses an emulator for the MIPS architecture. Using an emulator has many advantages over using the actual hardware. The biggest advantage is that the architecture described in these notes will exactly match the architecture implemented by the emulator. You can download exactly what you need to use to follow these notes. The emulator runs on most common desktop computers; PC, Mac, or even ... MIPS.

Question 12

Is it possible to run an emulator for a MIPS processor on an actual hardware MIPS processor?

Answer

Of course. Say that the emulator is written in C. Compile the emulator and run it on a MIPS computer. Now the program running on the MIPS is a MIPS emulator. This is a very computer-science-like notion.

Separate translation

An emulator running on the processor it is emulating is often used for debugging. Working with an emulator is usually more convenient than dealing with the hard silicon of the actual hardware.

A true computer nut (a "hacker", in the correct sense) will wonder if an emulator of (say) an Apple can run on an emulator of (say) an Intel machine that is running on a MIPS machine. Yes, as long as the various emulators exist.

For very many years (in computer years) assembly language was used for serious enterprise-wide programming for one reason: separate source files could be individually assembled, and later combined (linked) into the full executable. Each source file was assembled into an object module. This is called separate assembly (or separate translation).

An object module is a file that contains a machine language program that is not quite ready to run. It may not be ready to run for several reasons: the source code might not be completely translated (since more information is needed), memory locations for code and data might not be assigned, and more code is needed before the program is complete. An assembler creates an object module for each source file of assembly language.

Question 13

(Software Engineering Question:) Why translate many individual source files? Why not have one, big, complete program that translates into a complete, ready-to-run executable?

Answer

Enterprise-wide programs are hundreds of thousands of lines long and take hundreds of programmers and support staff. It just would not work if they were all working on one big monster source program.

Load modules

In assembly language the pieces of a big application program can be written as separate source files and assembled into separate object modules. The separate object modules are then combined by a linker into a load module, an executable file.

This is how all modern software of any appreciable size is written. The object modules do not need to be created from assembly language source. A compiler of a high level language (such as "C") creates object modules that look the same as those from the assembler. In the picture, object module A might be from an assembly program, object module B might be from a FORTRAN program, and object module C might be from a COBOL program.

For many years, the only common languages that supported separate translation were Assembly, FORTRAN, and COBOL. For many years, the only common languages used in production were Assembly, FORTRAN, and COBOL. BASIC did not support separate compilation; BASIC was never used for writing big applications. Pascal did not support separate compilation; Pascal was never used for writing big applications. C supported separate compilation; C is now the dominant language for writing applications.

Question 14

C compilers come with libraries of useful functions. The standard math library contains functions like sin, cos, and rand. What do you suppose a software library is?

Answer

A library is a collection of object modules which can be linked to the object module of your program.

Chapter quiz

Question 1

What is the architecture of a processor?

  • (A) the style and colors for the case and monitor
  • (B) the type of operating system and software that the computer runs
  • (C) the shape of the chip and the layout of its connector pins
  • (D) a description of the basic components of a processor chip and of its basic operations
Answer

D

Question 2

What language allows the programmer to program the processor at the architectural level?

  • (A) assembly language
  • (B) Java
  • (C) FORTRAN
  • (D) C
Answer

A

Question 3

What is the machine cycle?

  • (A) One machine cycle consists of all the steps taken in executing a program
  • (B) A machine cycle is how a cold computer is booted into running an operating system
  • (C) A machine cycle is the process through which one machine instruction is executed
  • (D) A machine cycle is the steps through which a byte is fetched from memory
Answer

C

Question 4

What are the three steps in the machine cycle?

  • (A) fetch, increment, execute
  • (B) increment, fetch, execute
  • (C) load, compile, run
  • (D) wash, rinse, spin dry
Answer

A

Question 5

What is a machine instruction?

  • (A) a pattern of bits that corresponds to one unit of data
  • (B) a signal sent across the system bus that controls the operation of the computer
  • (C) a pattern of bits that asks for one fundamental operation of the processor
  • (D) a signal sent by the system clock that starts one machine cycle
Answer

C

Question 6

What part of the processor indicates which machine instruction is next in line for execution?

  • (A) The address bus
  • (B) The memory address register
  • (C) The program counter
  • (D) The system clock
Answer

C

Question 7

What is a register?

  • (A) a part of the processor that performs an operation
  • (B) a part of the processor that keeps a log of operations
  • (C) the part of the operating system that oversees what programs are selected for execution
  • (D) a part of the processor that holds a bit pattern
Answer

D

Question 8

Do all processor chips use the same machine language?

  • (A) No. Machine language is an engineering decision that is unique to each processor family.
  • (B) No. Each individual processor chip has its own unique machine language.
  • (C) Yes. Machine language is a fundamental characteristic of all processors.
  • (D) Yes. An International Committee designed the machine language that all processors now use (after the year 2000).
Answer

A

Question 9

Assemblers and compilers usually translate a source program into machine instructions contained in what type of file?

  • (A) include file
  • (B) binary file
  • (C) object module
  • (D) hidden file
Answer

C

Question 10

What type of program uses software to imitate the hardware operation of a particular type of processor?

  • (A) imitator
  • (B) assembler
  • (C) translator
  • (D) emulator
Answer

D

Analog and Binary Signals

Everyone knows that computers are "digital" and that they use "binary" numbers. You probably have some idea of what these terms mean. But we need to be clear about their precise meaning and to be clear about why computers are digital.

Chapter Topics:

  • Binary signals
  • Analog signals
  • Advantages of Binary
  • Bits
  • Noisy signals

Study these topics carefully if you want to know what is really going on with computers.

Question 1

Why is a digital wristwatch called "digital?"

Answer

Because it shows time using definite digits, rather than positions of hands that have to be measured (such as on an analog watch). (It would be less correct to say "because it has a computer inside.")

Binary

Binary means "two states." The two states are sometimes called "1" and "0", or called "true" and "false", or called "on" and "off", (or other names.) The essential characteristic is that a single binary device can be in just one of two possible states.

A bit is a single "on/off" value.

A good example is a toggle switch, such as a light switch. You can turn it "on" or "off" but not (in normal operation) anything else. A light switch holds one bit of information.

A light dimmer is not a binary device: it has many positions between "off" and "fully on". If you want a light dimmer to be set to 25%, you must carefully adjust it.

Question 2

Which of the following is a binary device:

  • The ignition switch of an automobile.
  • The hour hand of a clock.
  • A button on an electronic calculator.
  • The volume control on a stereo.
Answer

A button on an electronic calculator.

Why computers use binary

The ignition switch of an automobile is discrete it has definite states but there are usually more than two states (off, running, start, acc...) A button on a calculator is a binary device. It is either on or off. Ordinarily it is "off." When you push it, it is "on." It springs back to "off" when you release it, which is different from a toggle switch, but it still is a binary device.

There are many advantages to binary. Here are four (somewhat overlapping) important reasons for using binary:

  1. Simple and easy to build.
  2. Unambiguous signals (hence noise immunity).
  3. Flawless copies can be made.
  4. Anything that can be represented with some sort of pattern can be represented with patterns of bits.

These characteristics of binary were realized by Claude Shannon, a mathematician at Bell Telephone Laboratories. His 1948 paper A Mathematical Theory of Communication is the foundation of information theory and much of computer science.

Question 3

Which is easier to build:

  • An on/off switch.
  • A light dimmer.
Answer

An on/off switch.

Advantages of binary 1: Simple, easy to build

Lightbulb switch status

An on/off switch is simple and easy to build. An on/off switch moves two pieces of metal together or moves them apart. A light dimmer must gradually and smoothly change the current that reaches the light. It has more components than an on/off switch and must be carefully assembled. An accurate dimmer (where 25% means exactly 25%) is even harder to build.

The same is true for the tiny devices inside of a silicon chip. On/off switches are relatively easy to fabricate. Easy to build means that the devices are cheap, small, and reliable, and millions of them can be put in a small area.

Question 4

Which of the following methods for producing books is simple and easy?

  • Each book is individually made by scratching marks onto tablets of wet clay.
  • Each book is individually made by copying the characters onto paper with pen and ink.
  • Many copies of the book are made by carving flat wooden blocks with the text then printing the text on paper.
  • Many copies of the book are made by setting movable type and printing the text on paper.
Answer

Setting type.

Advantages of binary 2: Unambiguous signals

Carving a block of wood into a book page requires high technical and artistic skill. The task is complex and labor intensive. A small mistake might ruin the whole block. The Renaissance woodcarvers were as skilled as woodcarvers ever have been.

Setting type is comparatively easy. Little artistic or technical skill is needed. Individual pieces of type are just dropped into place. The method is robust and reliable; mistakes can be corrected. The type can be reused many times.

It is a paradox that advances in technology often lead to simple methods. Woodcarving is complex; setting type is easy. The computer revolution (ca. 1950—) is often compared to the Gutenberg revolution (ca. 1450—).

Review the advantages of binary:

  1. Simple; easy to build.
  2. Unambiguous signals (hence noise immunity).
  3. Flawless copies can be made.
  4. Anything that can be represented with patterns can be represented with patterns of bits.
Question 5

Which is easier to do: (a) determine exactly how bright a light is, or (b) decide if it is on or off?

Answer

On or Off.

Old north bit

Unambiguous Signals: Consider Paul Revere, waiting for news of the attack of the British troops. He is expecting to see a signal lantern in the tower of Old North Church telling him how the British are attacking:

1.32456 if by land, 1.71922 if by sea.

The signal shines out! ...and Paul Revere's famous ride is delayed for several hours as he tries to figure out just how bright that signal is.

Lack of ambiguity is a tremendous advantage. The signal that Paul Revere was actually waiting for that night in 1775 was:

One (lantern) if by land, and two (lanterns) if by sea.

...an easily interpreted signal. All Paul Revere had to do was count. Such signals are called discrete because they have a fixed number of definite states. Sometimes the word digital is used to mean the same thing.

Question 6

Why can an abacus be regarded as a digital computer.

Answer

The computation is done by moving beads into definite positions. A bead is either placed where it counts as part of a number, or it is placed where it does not count. This "all or nothing" operation means that an abacus is a discrete device.

An analog signal

An analog signal may continuously change in value. Its values can be anything within a range of values, and its exact value at any time is important. The graph below represents an analog signal. The exact value at each time is part of the information it contains. For example, the value at time "T2" must be measured exactly.

Now say that you are observing the voltage of a wire. It has been agreed that any voltage below a threshold will be counted as an "off" signal, and that any value above the threshold will be counted as an "on" signal.

Question 7

At time "T2", is the signal "on" or "off"?

Answer

ON

The analog signal (continuously changing voltage signal) moves up and down, but at time "T2" it is clear that it is above the threshold. Exact measurement is not needed.

Binary signal

Analog signals continuously change in value. By using a threshold, analog signals can represent binary data ("on/off" data). It is easy and fast (for electronics, as well as for humans) to determine if a voltage is above or below a threshold. The figure shows a signal that transmits "off" then "on". (The signal is examined at times T1 and T2.)

Question 8

Is it clear that the signal is "off" at time T1 and "on" at time T2?

Answer

Yes

Imperfect transmission

The "ons" and "offs" of the previous signal are clear. But what if the signal is sent down a long wire and someone nearby turns on a vacuum cleaner? The whirling and sparking electric motor creates a great deal of electrical noise. The graph shows the signal at the other end of the wire.

Even though the signal is noisy (at the analog level), the binary values are transmitted perfectly. You (and the electronics) can still tell that at time T1 the signal represents "off" and that at time T2 the signal represents "on". The receiving end just needs to get the binary values.

Since only the "on" "off" information matters, the analog noise is irrelevant, and the original signal is received perfectly (so far as the binary information goes.)

Question 9

If the signal were regarded as an analog signal, and exact values were important, would some information present in the first signal (before the noise) have been lost?

Answer

Yes if the signals represented a singer's voice, the noisy signal would sound, er.. well... noisy. After just one copy, information has been lost.

Advantages of binary 3: Flawless copies can be made

Review the advantages of binary:

  1. Simple; easy to build.
  2. Unambiguous signals (hence noise immunity).
  3. Flawless copies can be made.
  4. Anything that can be represented with some sort of pattern can be represented with patterns of bits.

Flawless copies can be made: The receiving end of the signal is only interested in the binary values. All it has to do it check if the signal is above or below the threshold. This can be done perfectly (as long as the noise is not too great.) For example, here is the noisy signal with the "on"/"off" values recovered from it:

The original signal has been recovered flawlessly. This process can occur as many times as needed with a perfect copy made each time. This is essential in a computer system, where bit patterns (patterns of one and zero, or on and off) are copied back and forth between the processor and memory millions of times a second. The copies have to be perfect.

Question 10

Something might be wrong here. Is the signal "on" or "off" at the time "x"? This is not easy to tell. What is worse, a different amount of noise changes the answer. What can be done about this problem? (Hint: must the value of the signal be known at all times?)

Answer

The system is built so that the signal is tested only at particular times, and that changes in the signal occur between these times.

Clocks

Digital systems are built so that the "on" "off" (binary) value is only tested at certain times, giving the wire (or transistor, or...) a chance to change its state between these times. This is why computer systems have a "clock" to keep all these times synchronized. So faster clocks mean wires can be tested more times per second, and the whole system runs faster.

Processor chips (and the computers that contain them) are often described in terms of their clock speed. Clock speed is measured in Hertz, where one Hertz is one clock tick per second.

The symbol MHz means mega Hertz, a million clock ticks per second. The symbol GHz means giga Hertz, a billion clock ticks per second.

A 700 MHz processor checks binary values 700 million times in each second. In between these times values are allowed to change and settle down. The faster a processor chip is, the more times per second values can be tested, and the more decisions per second can be made.

Question 11

Which is faster, a 2 GHz processor or a 4 GHz processor?

Answer

The 4 GHz processor, since it checks values 4 billion times per second (twice as many as the 2 GHz processor).

(However, if the processors are different types there are other factors besides clock speed that determine how much each processor can do in a second.)

Advantages of binary representation 4: Representing anything

Recall that last advantage of binary:

  • Anything that can be represented with patterns can be represented with patterns of bits. Since data of all kinds is stored in computer memory (main and secondary) using the same electronic methods, this means that endless perfect copies can be made of any type of data or program.

This idea is that any system of symbols can be translated into bit patterns. An example is how English characters are represented as eight-bit patterns. The agreement about what patterns represent what characters is called ASCII. The hardware and the software of a computer system (usually) follow this agreement when the data is "text". (You will learn more about this later). Other types of data (non-character data) are represented using other methods.

Question 12

Can characters from alphabets other than English be represented?

Answer

Of course. Any type of symbol at all can be assigned a binary pattern to represent it.

More on representing anything in binary

Japanese and Chinese characters, also, have been translated into bit patterns, and computers can manipulate those symbols just as easily as ASCII. Unicode is an agreement created by an international committee on how to represent characters using 16 bits. Here are 16 bits 111110011111110 and here is the character it represents in Unicode: 茶

Say that the international committee decides to represent a new Chinese character. How can they do this? Easy: they find a bit pattern not yet used to represent any symbol and assign the new character to that pattern.

The correspondence between human language symbols and bit patterns is arbitrary. All you have to do is be sure that you are using enough bits so that each symbol of the language has a unique bit pattern to represent it.

Question 13

Can printed music be represented using binary?

Answer

Sure — any symbols can. There are "music processor" programs for printed music that work like word processor programs for printed text.

Smybols and patterns

Recall that last advantage of binary:

  • Anything that can be represented with patterns can be represented with patterns of bits.

What about representing things other than the written characters of a language? This is a deep topic, and entire books have been written on it. Here is a very sloppy discussion: Pick some subject. Use English sentences to describe it. Represent those sentences in ASCII (characters encoded as bit patterns.) Now the subject is represented in binary. If something can be represented in English, then it can be represented in binary.

Notice that this says nothing about "meaning" or "understanding." Printed books don't understand their own contents. A digital version of the book (say on CD ROM) doesn't understand the book, either. It merely holds the information, waiting for a human mind to do the understanding. However the book has been represented as bit patterns.

Nobody said that binary representations are easy to use. Some representation methods are very useful for computers (for instance, using binary patterns to represent numbers), others are nearly useless. Much of the work that computer scientists do is figuring out how to represent things using binary in ways that are useful. For example, much work has been done in the last ten years in figuring out how best to represent image and audio data.

Important Point:

All that computer memory holds is bit patterns. What those bit patterns represent depends on how they are used.

Question 14

Sometimes people say, "All that a computer can handle is numbers. It doesn't understand anything else." Do you think that this is correct?

Answer

No. Any type of symbolic data can be represented using binary, not just numbers. At the electronic level, everything is a binary pattern (which some people call a "number"), so the statement is sort-of correct.

Chapter quiz

Question 1

What does the word binary mean?

  • (A) Binary means "containing a computer."
  • (B) Binary means "having only two states."
  • (C) Binary means "having a discrete number of values."
  • (D) Binary means "using electronics to do arithmetic."
Answer

B

Question 2

What is a bit?

  • (A) A bit is a single binary value.
  • (B) A bit is a collection of several bytes.
  • (C) A bit is a single character stored in main memory.
  • (D) A bit is a small unit of computer time.
Answer

A

Question 3

Which of the following is NOT an advantage of building computers out of binary devices?

  • (A) Binary devices are simple and easy to build.
  • (B) Binary signals are unambiguous.
  • (C) Binary devices are much faster than decimal devices.
  • (D) Patterns of bits can be used to represent anything symbolic.
Answer

C

Question 4

What is true of an analog signal?

  • (A) An analog signal has a discrete number of states.
  • (B) An analog signal is the only way that music can be recorded.
  • (C) An analog signal can never be converted into a binary signal.
  • (D) An analog signal is usually continuously changing in value.
Answer

D

Question 5

If an analog signal picks up some noise, has information been lost?

  • (A) No — electronics can just ignore the noise.
  • (B) No — information has been added to the signal.
  • (C) Maybe — it depends on how loud the noise is.
  • (D) Yes — the noise hides the exact values of the original signal.
Answer

D

Question 6

If a binary signal picks up some noise, has information been lost?

  • (A) No — the exact value of the bits can be determined, as long as the noise is not too great.
  • (B) No — binary signals can't pick up any noise.
  • (C) Yes — the exact value of the bits cannot be determined.
  • (D) Yes — the signal will have extra bits in it because of the noise.
Answer

A

Question 7

Why does a computer have a clock?

  • (A) The state of binary signals is measured only at specific instants in time.
  • (B) A clock is needed to check how fast signals are changing.
  • (C) A clock is needed to check that voltage levels are correct.
  • (D) A clock is used only with application programs that need to know the current time.
Answer

A

Question 8

Can Japanese writing be represented in a computer?

  • (A) No — only English and English-like languages can be represented.
  • (B) No — only languages with an alphabet can be represented.
  • (C) Yes — but a special processor chip is needed.
  • (D) Yes — since it is symbolic, and anything symbolic can be represented.
Answer

D

Question 9

Can English writing be represented with analog signals?

  • (A) No—only binary signals can represent symbolic data.
  • (B) No — it is not symbolic.
  • (C) No — analog signals don't represent anything.
  • (D) Yes — just read out loud into a microphone.
Answer

D

Question 10

Why is it important that unlimited perfect copies can be made of data represented in binary?

  • (A) Transmitting data over the Internet involves making many copies of the data.
  • (B) Application programs such as wordprocessors and computer games must be perfect copies of the original in order to run.
  • (C) Because data are copied back and forth between parts of a computer system many times per second.
  • (D) All of the above.
Answer

D

Bits and Bit Patterns

Computers represent data and instructions with patterns of bits. You must become familiar with bit patterns! This chapter will help you. It discusses the fundamentals of bit patterns.

Chapter Topics:

  • Patterns of bits.
  • The number of patterns that can be formed for N bits.
  • How to systematically list all the patterns for N bits.
  • Multiplying powers of two.
  • Bytes, kilobytes, megabytes, and gigabytes.
  • Names for four-bit patterns.
  • Hexadecimal names for bit patterns.
  • Octal names for bit patterns.

In most computer documentation, 8 contiguous bits are called a byte. A bit holds a zero or a one, possibly representing the on/off condition of a switch.

Question 1

How many patterns can be formed with a single bit?

Answer

Two 0 and 1 (or "off" and "on", or "false" and "true")

Patterns of bits

A bit can be 0 or 1. With one bit there are two possible patterns. How many patterns can be formed with two bits? Here is a complete list:

    0 0
0 1
1 0
1 1

Looks like 4 patterns.

Question 2

Is the pattern 01 different from the pattern 10?

Answer

Yes the position of a bit matters.

How many patterns with three bits

How many patterns can be formed with three bits? Let's list them:

    0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Looks like 8 patterns.

Question 3

Is the number of patterns that can be formed with N bits greater than the number of bits?

Answer

Yes much greater. This simple fact is of profound importance to computer science.

Listing patterns systematically

There is a standard method for listing all of the patterns that can be formed with a given number of bits. First, list all of the patterns that can be formed with one bit:

0
1

To increase the number of bits (from one to two) make two copies of the list:

0
1

0
1

Within each copy, each row is unique. Now, make each row in the combined list unique. Do this by putting a "0" in front of each line of the first copy, and a "1" in front of each line of the second copy:

0 0
0 1

1 0
1 1

Now each line is unique and you have a complete list of the possible patterns of two bits. The number of unique patterns with 2 bits is double that with 1 bit.

For additional bits, repeat the trick for each new bit.

Question 4

How many patterns can be formed from three bits?

Answer

8 patterns can be formed from three bits.

How many patterns from three bits

Repeat the trick. Make two copies of the table for two bits:

  0 0
0 1
1 0
1 1

0 0
0 1
1 0
1 1

Now make each row unique by putting a "0" in front of the first group and a "1" in front of the second group:

0 0 0
0 0 1
0 1 0
0 1 1

1 0 0
1 0 1
1 1 0
1 1 1

Now you have all the patterns that can be formed from three bits.

Question 5

How many patterns can be formed from N bits?

Answer

Twice the number of patterns that can be formed from (N-1) bits.

How many patterns from N bits

The list of patterns for three bits has 8 lines (patterns). To form the list of patterns for 4 bits, make two copies of the list for 8 bits. This gives you 16 lines. Each line is made unique by prefixing the first half with "0" and the second half with "1".

Of course, the trick can be repeated as many times as you like. Adding one more bit doubles the number of patterns. The table shows the number of patterns for 1, 2, 3 and 4 bits.

Number of BitsNumber of PatternsNumber of Patterns as power of two
12212^1
24222^2
38232^3
416242^4

How many patterns with 5 bits? Make two copies of the 4-bit patterns (16 patterns per copy). Make the patterns unique by prefixing "0" to the first 16 patterns and "1" to the second 16. You now have 16×2=2516\times 2 = 2^5 unique patterns. This demonstrates the following:

Number of possible patterns of N bits=2N\text{Number of possible patterns of $N$ bits} = 2^N

Memorize this fact. Better yet, make lists of patterns (as above) and play around until you understand. Do this now. This is an essential fact. If you allow yourself to get muddled on it, you will waste much time in this and future courses.

How many patterns can be formed with 10 bits? Use the formula:

210=10242^{10} = 1024

This number occurs often in computer science. 1024 bytes is called a kilobyte, abbreviated K and pronounced "Kay".

Question 6

In the past, some computers used 16 bits to form memory addresses. Assuming no special tricks (which such limited machines often used), how many bytes maximum could be held in main storage?

Answer

64K bytes:

216=2(6+10)=26×210=64K2^{16}=2^{(6+10)}=2^6\times 2^{10}=64\mathrm{K}

More about patterns

Number of bitsNumber of patternsNumber of patterns as power of two
12212^1
24222^2
38232^3
416242^4
532252^5
664262^6
7128272^7
8256282^8
9512292^9
1010242102^{10}

Many calculations involving bit patterns use the following familiar fact of arithmetic. (Although the fact is familiar, confusion is even more familiar. Be sure you know this factoid.)

2(N+M)=2N×2M2^{(N+M)}=2^N\times 2^M

It is not too much work to extend the table, as shown above. You can always make this table from scratch, but memorizing a few key values does not hurt.

The numbers of patterns that can be formed with 10 or more bits are usually expressed as multiples of 1024 (= 210) or in "Megs" (= 220). For example, how many patterns can be formed from 24 bits?

224=24×220=16 Meg2^{24} = 2^4\times 2^{20} = \text{16 Meg}

The power of two (24) splits into a small part (242^4) and a part that has a name (220=Meg2^{20} = \mathrm{Meg}). This is a useful trick you can use to amaze your friends and impress employers.

Some audio cards use 12 bits to represent the sound level at an instant in time (12 bits per sample). How many signal levels are represented?

212=22×210=4Klevels2^{12} = 2^2\times 2^{10} = \mathrm{4K\,levels}
Question 7

You wish to save a GIF image using either 6 bits per pixel or 8 bits per pixel. Saving the image with 8 bits per pixel takes somewhat more memory. Which should you choose?

Answer

Unless memory is at a premium, use 8 bits per pixel. With 6 bits, the image could only have 26=642^6 = 64 colors; with 8 bits, it can have 28=2562^8 = 256 colors, a considerable improvement.

Pattern names

Hexadecimal names
nibblepattern namenibblepattern name
0000010008
0001110019
001021010A
001131011B
010041100C
010151101D
011061110E
011171111F

Consider the following pattern:

0010100010101010

It is not easy to work with. It is convenient to break bit patterns into 4-bit groups (called nibbles):

0010 1000 1010 1100

There are 16 (i.e., 242^4) possible patterns in a nibble. Each pattern has a name, as seen in the table.

You might be tempted to call those 4-bit patterns "binary numbers". Resist that temptation. The bit patterns in computer main memory are used for very many purposes. Representing integers is just one of them. The fundamental concept is "bit patterns". Don't confuse this concept with one of its many uses: "representing numbers".

The above bit pattern can be written using the pattern names:

0010 1000 1010 1100 = 28AC

Bits are grouped into nibbles starting at the right. Then each nibble is named. This method of giving names to patterns is called hexadecimal.

Question 8

Name the following patterns:

0001 0001    
0011 1001
1011 1111
0100 0110
0000 0000
Answer
0001 0001     11
0011 1001 39
1011 1111 BF
0100 0110 46
0000 0000 00 (be sure to show both zeros)

More hex practice

If there are not enough bits at the left to form a complete group of four, add zero bits to the left, (but be sure that it is clear by context how many bits you are describing). For example:

1010000010000010     =  
1010 0000 1000 0010 = A082

Another example:

10100110101111      =  
10 1001 1010 1111 =
0010 1001 1010 1111 = 29AF

Usually '0x' is placed at the front of a pattern name to show that it is a hexadecimal pattern name:

0x0010  =  0000 0000 0001 0000
0xFACE = 1111 1010 1100 1110

Adding zeros to the left of a pattern creates a new pattern. The new pattern has its own name. 0x0 = 0000 is a different pattern than 0x00 = 0000 0000. Sadly, people are not consistent about this, and depending on context, both patterns might be called "0x0".

Keep in mind that hexadecimal pattern names are used by humans for talking about bit patterns. Inside the computer there are only bits and their patterns. Hexadecimal is used in books and documents (outside the computer) to describe these bit patterns.

Question 9

Name the following patterns; include 0x in the name:

0000 1010 0001 0001    
0001 0010 1001 1010
1111 1010 1101 1110
0011 0110 1100 0000
0000 0000 0000 0000
Answer
0000 1010 0001 0001     0x0A11
0001 0010 1001 1010 0x129A
1111 1010 1101 1110 0xFADE
0011 0110 1100 0000 0x36C0
0000 0000 0000 0000 0x0000 (be sure to show all zeros)

Octal

Sometimes documentation describes bit patterns in groups of three. Three-bit groups are named using the first eight pattern names of hexadecimal. This method is called octal notation. A bit pattern can be named using hexadecimal names, octal names, or many other notations.

01101010 = 01 101 010 =  152 (octal)
01101010 = 0110 1010 = 0x6A (hex)

Octal is awkward to use with 8-bit bytes. Bytes don't evenly split into octal pattern names. But you should know about it. Historically, some computer documentation used octal pattern names. Also, in several programming languages (C and Java among them) octal notation is indicated by a leading zero:

0152    (octal)    = 001 101 010 
0x152 (hex) = 0001 0101 0010
152 (decimal) = 1001 1000

When the number of bits is not a multiple of three it is conventional to add zero bits to the left, and then to name the pattern as usual. This happens frequently because computer memory is organized into 8-bit bytes, which do not divide evenly into groups of three.

I have lost an unfortunate number of hours with buggy programs, only to discover a constant buried deep in the code that started with a "0" when it should not have.

Question 10

What is the OCTAL pattern name of the following bit patterns:

111 010 001    
100 011 010
011011110
11000000
Answer
111 010 001     0721
100 011 010 0432
011011110 0336
11000000 0300

Chapter quiz

Question 1

How many patterns can be formed with a single bit?

  • (A) 1
  • (B) 2
  • (C) 4
  • (D) 8
Answer

B

Question 2

How many patterns can be formed with three bits?

  • (A) 1
  • (B) 3
  • (C) 8
  • (D) 12
Answer

C

Question 3

How many patterns can be formed from N bits?

  • (A) NN
  • (B) N2N^2
  • (C) 2N2^N
  • (D) 2×N2\times N
Answer

C

Question 4

What is 24×232^4 \times 2^3?

  • (A) 828^2
  • (B) 262^6
  • (C) 272^7
  • (D) 2122^{12}
Answer

C

Question 5

How many bits are in a nibble?

  • (A) 2
  • (B) 4
  • (C) 8
  • (D) 16
Answer

B

Question 6

What is the name for the bit pattern 0000 0010?

  • (A) 0x0002
  • (B) 0x02
  • (C) 0xA0
  • (D) 0x201
Answer

B

Question 7

What is the name for the bit pattern 101010?

  • (A) 0xA2
  • (B) 0x222
  • (C) This pattern can not be named.
  • (D) 0x2A
Answer

D

Question 8

Say that you read that a particular computer "uses hexadecimal". What is being described?

  • (A) ...the fundamental hardware of the processor chip.
  • (B) ...a convention used in written documentation of the computer.
  • (C) ...the type of arithmetic carried out by the computer.
  • (D) ...the type of signals used on the computer's bus.
Answer

B

Question 9

What is the name for the convention where bits are named in groups of three?

  • (A) Trinary
  • (B) Sextuple
  • (C) Tridecimal
  • (D) Octal
Answer

D

Question 10

How many bytes are in a kilobyte?

  • (A) 8
  • (B) 1000
  • (C) 1024
  • (D) 4068
Answer

C

Computer Organization

This chapter discusses how computer systems are organized, with special attention paid to main memory. Most of this you probably know already, but look it over anyway.

Chapter Topics:

  • Components of a Computer System
  • Device Controllers
  • Main Memory
  • Addresses
  • Virtual Memory
  • Cache Memory
  • Contents of Memory
Question 1

Does a computer system based upon one type of processor chip (say MIPS) look about the same as a system based upon another type of chip (say Pentium)?

Answer

Yes. The main components are about the same and work about the same way.

Computer system components

The diagram shows a general view of how desktop and workstation computers are organized. Different systems have different details, but in general all computers consist of components (processor, memory, controllers, video) connected together with a bus. Physically, a bus consists of many parallel wires, usually printed (in copper) on the main circuit board of the computer. Data signals, clock signals, and control signals are sent on the bus back and forth between components. A particular type of bus follows a carefully written standard that describes the signals that are carried on the wires and what the signals mean. The PCI standard (for example) describes the PCI bus used on most current PCs.

The processor continuously executes the machine cycle, executing machine instructions one by one. Most instructions are for an arithmetical, a logical, or a control operation. A machine operation often involves access to main storage or involves an i/o controller. If so, the machine operation puts data and control signals on the bus, and (may) wait for data and control signals to return. Some machine operations take place entirely inside the processor (the bus is not involved). These operations are very fast.

Question 2

Do you think that the various components can put signals and data on the bus at any arbitrary time?

Answer

No. The various devices must cooperate somehow so their data and signals don't get mixed.

Input/output controllers

The way in which devices connected to a bus cooperate is another part of a bus standard.

Input/output controllers receive input and output requests from the central processor, and then send device-specific control signals to the device they control. They also manage the data flow to and from the device. This frees the central processor from involvement with the details of controlling each device. I/O controllers are needed only for those I/O devices that are part of the system.

Often the I/O controllers are part of the electronics on the main circuit board (the mother board) of the computer. Sometimes an uncommon device requires its own controller which must be plugged into a connector (an expansion slot) on the mother board.

I/O controllers are sometimes called device controllers. The software that directly interacts with a device controller is called a device driver. When you install a new device on your computer (say, a new graphics board) you must also install a device driver for it.

Question 3

(Review:) Is there a difference between the memory used to hold programs and the memory used to hold data?

Answer

No. Potentially any byte of main memory can hold part of a program or part of some data.

Main memory

DescriptorBytes
kilobyte210=10242^{10}=1024 bytes
megabyte220=10242^{20}=1024 kilobytes
gigabyte230=10242^{30}=1024 megabytes
terabyte240=10242^{40}=1024 gigabytes

In practice, data and instructions are often placed in different sections of memory, but this is a matter of software organization, not a hardware requirement. Also, most computers have special sections of memory that permanently hold programs (firmware stored in ROM), and other sections that are permanently used for special purposes.

Main memory (also called main storage, or just memory) holds the bit patterns of machine instructions and the bit patterns of data. Memory chips and the electronics that controls them are concerned only with saving bit patterns and returning them when requested. No distinction is made between bit patterns that are intended as instructions and bit patterns that are intended as data. The amount of memory on a system is often described using the terms in the table.

These days (Dog Days of summer, 2015) the amount of main memory in a new desktop computer ranges from 4 gigabytes to 32 gigabytes. Hard disks and other secondary storage devices hold several terabytes.

Question 4

What is (on most computers) the smallest addressable unit of memory?

Answer

A byte.

Address

Each byte of main storage has an address. Most modern processors use 32-bit addresses, so there are 2322^{32} possible addresses. Think of main storage as if it were an array:

byte[0x00000000 ... 0xFFFFFFFF] mainStorage;

A main storage address is an index into memory. A 32-bit address is the address of a single byte. Thirty-two wires of the bus contain an address (there are many more bus wires for timing and control).

Sometimes people talk about addresses like 0x2000, which looks like a pattern of just 16 bits. But this is just an abbreviation for the full 32-bit address. The actual address is 0x00002000.

The first MIPS processors (designed in 1985) used 32-bit addresses. From 1991 to present, top-end MIPS processors use 64-bit addresses. The MIPS32 chip is a modern chip designed for embedded applications. It uses 32-bit addresses, since embedded applications often don't need 64 bits. Recent processor chips from AMD and Intel have 64-bit addresses, although 32-bit versions are still available.

The assembly language of this course is for the MIPS32 chip, so we will use 32-bit addresses. The assembly language of the 64-bit MIPS chips is similar.

Question 5

What is the hexadecimal name for the 32-bit pattern that consists of all 1 bits? (Hint: look at the picture.)

Answer

0xFFFFFFFF

Virtual memory

The MIPS has an address space of 2322^{32} bytes. A Gigabyte is 2302^{30}, so the MIPS has 4 gigabytes of address space. Ideally, all of these memory locations would be implemented using memory chips (usually called RAM).

On modern computers, the full address space is present no matter how much RAM has been installed. This is done by keeping some parts of the full address space on disk and some parts in RAM. The RAM, the hard disk, some special electronics, and the operating system work together to provide the full 32 bit address space. To a user or an applications programmer it looks as if all 2322^{32} bytes of main memory are present.

This method of providing the full address space by using a combination of RAM memory and the hard disk is called virtual memory. The word virtual means "appearing to exist, but not really there." Some computer geeks have a virtual social life.

Question 6

Which is faster: access to physical (RAM) memory or access to the hard disk?

Answer

Physical memory.

Cache memory

Disk access is slow compared to RAM access. Potentially, using a combination of real memory and disk memory to implement the address space could greatly slow down program execution. However, with clever electronics and a good operating system, virtual memory is only slightly slower than physical memory.

Computer systems also have cache memory. Cache memory is very fast RAM that is inside (or close to) the processor. It duplicates sections of main storage that are heavily used by the currently running programs. The processor does not have to use the system bus to get or store data in cache memory. Access to cache memory is much faster than to normal main memory.

Like virtual memory, cache memory is invisible to most programs. It is an electronic detail below the level of abstraction provided by assembly language. Hardware keeps cache up to date and in synch with main storage. Your programs are unaware that there is cache memory and virtual memory. They just see "main memory". Application programs don't contain instructions that say "store this in cache memory", or say "get this from virtual memory". They only refer to the contents of main memory at a particular address. The hardware makes sure that the program gets or stores the correct byte, no matter where it really is.

Question 7

Since memory looks like an array of bytes, is it necessary for each item of data in memory to be one byte long?

Answer

No. Most data and instructions are several bytes long and occupy several consecutive memory addresses.

Contents of memory

The memory system merely stores bit patterns. That some of these patterns represent integers, that some represent characters, and that some represent instructions (and so on) is of no concern to the electronics. How these patterns are used depends on the programs that use them. A word processor program, for example, is written to process patterns that represent characters. A spreadsheet program processes patterns that represent numbers.

Of course, most programs process several types of data, and must keep track of how each is used. Often programs keep the various uses of memory in separate sections, but that is a programming convention, not a requirement of electronics.

Any byte in main storage can contain any 8-bit pattern. No byte of main storage can contain anything but an 8-bit pattern. There is nothing in the memory system of a computer that says what a pattern represents.

Question 8

When first turned on, many computer systems test their RAM by writing various patterns to various locations and then reading the patterns back. Do you think this is a good test?

Answer

It is a good test. The job of memory is to hold bit patterns, and to return them when requested, and that is what is tested.

Chapter quiz

Question 1

What is a the name for a group of parallel conductors on the main circuit board over which data and signals flow?

  • (A) PCB
  • (B) bus
  • (C) system cable
  • (D) device controller
Answer

B

Question 2

In which of the following lists are devices arranged in order of slowest to fastest for data movement into and out of the processor?

  • (A) main memory, hard drive, floppy disk
  • (B) floppy disk, main memory, hard drive
  • (C) floppy disk, hard drive, main memory
  • (D) hard drive, main memory, floppy disk
Answer

C

Question 3

What is the name for an electronic module that responds to requests from the central processor, by sending device-specific control signals to an I/O device?

  • (A) bus handler
  • (B) I/O module
  • (C) virtual device
  • (D) device controller
Answer

D

Question 4

What is the main difference between the section of memory that holds instructions and the section of memory that holds data?

  • (A) Data memory is arranged into bytes with addresses; instruction memory holds words without addresses.
  • (B) There is no difference. All memory does is hold bit patterns. It is up to the rest of the computer system to determine what those patterns mean.
  • (C) Data memory is connected to the data bus. Instruction memory is connected to the instruction bus.
  • (D) Data uses virtual memory; instructions use physical memory.
Answer

B

Question 5

In most modern processors, what is the smallest addressable unit of memory?

  • (A) bit
  • (B) byte
  • (C) 32 bits
  • (D) 64 bits
Answer

B

Question 6

How many memory addresses are there with a 32-bit bus?

  • (A) 2322^{32}
  • (B) 32
  • (C) 32232^2
  • (D) This depends on how much memory has been installed in the computer.
Answer

A

Question 7

How many bits are in the addresses of the MIPS 32 chip, the processor that is the subject of this course?

  • (A) 16
  • (B) 24
  • (C) 32
  • (D) 64
Answer

C

Question 8

On a modern computer, the processor "sees" the full address space even though there is less installed memory than that. What is this full address space called?

  • (A) virtual memory
  • (B) apparent memory
  • (C) RAM
  • (D) physical memory
Answer

A

Question 9

How is the illusion of a full address space maintained on a modern computer?

  • (A) Addresses on the system bus are divided between disk storage and RAM memory.
  • (B) The operating system, with the help of special electronics, uses both physical memory and disk storage to implement the address space.
  • (C) Most programs use far less than the full address space, so they don't notice that only part of it is there.
  • (D) The processor divides time into very small slices and changes the contents of memory after each slice.
Answer

B

Question 10

What is cache memory?

  • (A) The part of the hard disk that lists its contents.
  • (B) The part of the hard disk used for virtual memory.
  • (C) Read-only memory that holds basic I/O instructions.
  • (D) Memory inside the processor chip that is used to speed up main memory access.
Answer

D