What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

The CPU is the heart of the computer. A program is a sequence of instructions stored in main memory. When a program is run, the CPU fetches the instructions and executes or follows the instructions.

The fetch/decode/execute cycle

  • fetch - get the next instruction from main memory.
  • decode - determine what instruction to perform.
  • execute - perform the instruction.

Every program ends up as a sequence of basic instructions that consist of arithmetic and logic operations and control flow operations.

Arithmetic and logic operations include add, subtract, multiply, divide and comparison of values (equality, less than, greater than).

Control flow operations are used to determine what instruction to execute next. For example, based on the instruction, the program may skip or branch to another part of the instructions list.

You will learn the details of how CPUs process instructions in CS 271, Computer architecture and assembly language.

Main memory or RAM is used to store the program while it is executing and to store the data that the program is working with.

RAM details

  • The CPU is able to quickly access any location in RAM.
  • RAM is called volatile storage. Unlike persistent storage, when a computer is turned off or when a program finishes executing, the values stored in RAM are erased.
  • RAM is divided into storage units called bytes. A byte is a sequence of eight bits.
  • A bit is the smallest element of the RAM and it stores a binary digit, either a 0 or a 1. Every program and every data value in your computer is stored as sequences of Os and ls.

Secondary storage provides long lasting and persistent storage. Unlike RAM, data stored within secondary storage does not disappear when a computers is turned off or restarted. The most common form of secondary storage for large computers is a disk drive but computers can use other forms of secondary storage such as solid state drives which use memory chips that maintain data values without power.

Like main memory, secondary storage also stores information as sequences of 0s and 1s as bits and bytes.

We typically think of keyboards and mice but input devices can include cameras, microphones, and many other types of various sensors when you start thinking of computers embedded in cars, electronics, and almost any electrical device.

The information a computer sends to the outside world is called output. If a person is involved, output is typically sent to an output device such as the computer screen or a printer. Not all programs will output data to an output device. Instead, the output may be sent out over a computer network or stored in a database.

Now you are going to look at how the CPU can perform calculations, using a process known as the fetch-decode-execute cycle. Here, you have a representation of a CPU and RAM. The registers are also shown, where data can be temporarily stored.

Now you are going to look at how the CPU can perform calculations, using a process known as the fetch-decode-execute cycle.

Here, you have a representation of a CPU and RAM. The registers are also shown, where data can be temporarily stored.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

Fetch

The program counter (PC) starts at 0000. This means that the first address in RAM where the computer will look for an instruction is 0000.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

The computer needs somewhere to store the current address in RAM that it is looking for. This is what the memory address register (MAR) is for. The address 0000 is therefore copied into the MAR.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

A signal is now sent down through the address bus to the RAM. The control unit sends out a memory read signal, and the contents of the address 0000 are copied through the data bus to the memory data register (MDR).

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

As the data fetched during the fetch stage is an instruction, it is copied into the instruction register (IR).

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

As the first instruction has been fetched, the system is at the end of the fetch stage of the cycle. The program counter can be incremented by 1, so the system is ready to read the next instruction when the next fetch cycle starts.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

Decode

Now, the instruction needs to be decoded. It is sent via the data bus to the control unit, where it is split into two parts. The first part is the operation code or opcode, which in this example CPU is the first four bits. This is the command that the computer will carry out. The second part, in this case the second four bits, is the operand. This is an address in RAM where data will be read from or written to, depending on the operation.

The control unit can translate opcodes into instructions. So here the control unit translates the opcode 0101 into a LOAD FROM RAM instruction.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

Execute

Now, the command will be executed. The operand is copied to the MAR, as it provides the address of the data to be loaded (0100 in this case).

The data at address 0100 is then fetched from RAM and passed up the data bus to the MDR. As it is not an instruction but simply data, it is then passed to the accumulator (Acc).

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

This is a complete fetch-decode-execute cycle.

The 2nd Fetch, Decode and Execute Cycle

You will now run through the remaining two cycles of the program. The PC now holds 0001, so you fetch, decode, and execute the instruction at that address.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

  1. The PC is at 0001, so this is the next instruction to be fetched.
  2. The instruction opcode and address operand are placed in the IR, and the PC increased by 1 again.
  3. The instruction is decoded, while the address of the data to be acted upon is placed in the MAR. The instruction turns out to be ADD, which adds two pieces of data together.
  4. The new data is fetched from the address and eventually ends up in the accumulator, along with the results of the previous cycle.
  5. To finish off this stage, the two values in the accumulator are passed into the ALU, where they can be added together, as was instructed by the opcode.
  6. The result is then placed back into the accumulator.

That’s a second cycle complete.

The 3rd Fetch, Decode and Execute Cycle

The last cycle is for the instruction at 0010. It uses the opcode 0011, which is STORE and the operand 0110, which is the last address in the RAM shown.

What term is used to refer to the computer instructions that are executed by a CPU which are specific to each CPU?

So this cycle takes the results of the addition in the accumulator and stores it back into RAM at address 0110, as requested.

To recap, our program used three instructions to add two numbers and store the result in memory:

  1. The first instruction LOADed a piece of data from a specified address.
  2. The second ADDed this to the data found in another address.
  3. The final instruction STOREd the result of the addition back into a specified address in memory.

There is a lot of information to take in to understand the fetch-decode-execute cycle. Many people find it confusing when following it for the first time. You may find it helpful to run through this activity a second time.

This page contains sample answers to the quiz on Chapter 1 of Introduction to Programming Using Java. Note that generally, there are lots of correct answers to a given question.

Question 1:

One of the components of a computer is its CPU. What is a CPU and what role does it play in a computer?

Answer:

The CPU, or Central Processing Unit, is the active part of the computer. Its function is to execute programs that are coded in machine language and stored in the main memory (RAM) of the computer. It does this by repeating the fetch-and-execute cycle over and over; that is, it repeatedly fetches a machine language instruction from memory and executes it.

Question 2:

Explain what is meant by an "asynchronous event." Give some examples.

Answer:

An asynchronous event is one that occurs at an unpredictable time outside the control of the program that the CPU is running. It is not "synchronized" with the program. An example would be when the user presses a key on the keyboard or clicks the mouse button. (These events generate "interrupts" that cause the CPU to interrupt what it is doing and to take some action to handle the asynchronous event. After handling the event, the CPU returns to what it was doing before it was interrupted.)

Question 3:

What is the difference between a "compiler" and an "interpreter"?

Answer:

Compilers and interpreters have similar functions: They take a program written in some programming language and translate it into machine language. A compiler does the translation all at once. It produces a complete machine language program that can then be executed. An interpreter, on the other hand, just translates one instruction at a time, and then executes that instruction immediately. (Java uses a compiler to translate java programs into Java Bytecode, which is a machine language for the imaginary Java Virtual Machine. Java Bytecode programs are then executed by an interpreter.)

Question 4:

Explain the difference between high-level languages and machine language.

Answer:

Programs written in the machine language of a given type of computer can be directly executed by the CPU of that type of computer. High-level language programs must be translated into machine language before they can be executed. (Machine language instructions are encoded as binary numbers that are meant to be used by a machine, not read or written by people. High-level languages use a syntax that is closer to human language.)

Question 5:

If you have the source code for a Java program, and you want to run that program, you will need both a compiler and an interpreter. What does the Java compiler do, and what does the Java interpreter do?

Answer:

The Java compiler translates Java programs into a language called Java bytecode. Although bytecode is similar to machine language, it is not the machine language of any actual computer. A Java interpreter is used to run the compiled Java bytecode program. (Each type of computer needs its own Java bytecode interpreter, but all these interpreters interpret the same bytecode language.)

Question 6:

What is a subroutine?

Answer:

A subroutine is a set of instructions for performing some task that have been grouped together and given a name. Later, when that task needs to be performed, it is only necessary to call the subroutine by giving its name, rather than repeating the whole sequence of instructions.

Question 7:

Java is an object-oriented programming language. What is an object?

Answer:

An object consists of some data together with a set of subroutines that manipulate that data. (An object is a kind of "module," or self-contained entity that communicates with the rest of the world through a well-defined interface. An object should represent some coherent concept or real-world object.)

Question 8:

What is a variable? (There are four different ideas associated with variables in Java. Try to mention all four aspects in your answer. Hint: One of the aspects is the variable's name.)

Answer:

A variable is a memory location that has been given a name so that it can easily be referred to in a program. The variable holds a value, which must be of some specified type. The value can be changed during the course of the execution of the program.

Question 9:

Java is a "platform-independent language." What does this mean?

Answer:

A Java program can be compiled once into a Java Bytecode program. The compiled program can then be run on any computer that has an interpreter for the Java virtual machine. Other languages have to be re-compiled for each platform on which they are going to run. The point about Java is that it can be executed on many different types of computers without being recompiled.

Question 10:

What is the "Internet"? Give some examples of how it is used. (What kind of services does it provide?)

Answer:

The Internet is a network connecting millions of computers around the world. Computers connected to the Internet can communicate with each other. The Internet can be used for Email (which lets a user of one computer send a message to a user on another computer), file sharing (which is used to copy files between computers), and the World Wide Web (which lets a user view "pages" of information published on computers around the world).