What is a Computer Instruction? (Explained)

eComputerTips is reader-supported. When you buy through links on our site, we may earn a small commission without any additional cost to you.

What is a Computer Instruction?

Computer instructions typically refer to the set of codes that are usually given to the computer processor. These instructions contain several steps or processes to be carried out by the processor.

In terms of computer science and technology, a set of instructions refers to the single operation to be executed by the processor. It is the operational process of the processor that is typically defined by the instruction set.

KEY TAKEAWAYS

  • A computer cannot operate on its own and therefore needs instructions given to it so that it knows how to do a certain task.
  • Computer instructions are usually given by the users through different input devices such as keyboard, mouse and others.
  • All these instructions are usually stored in the hard drive of the computer or any other storage device and cannot be carried out unless these are run by the user.
  • Computer instructions are usually not specified in the machine code format but in an assembly language by the programmers or generated by compilers.
  • The program instructions are executed by a process called the instruction cycle which involves different phases such as fetching, decoding, reading and executing.

Understanding Computer Instructions

What is a Computer Instruction

The instruction sets are typically designed by prioritizing the requirements of the program as well as the processor.

Though the common concept of computer instructions refers to the set of commands given to the processor, in reality it can have varied meanings.

Looking beyond the computer processor, there can be another general definition of a computer instruction set which is a version of a constituent of an executable computer program. It basically prompts the computer to carry out a specific function.

Generally, the computer instructions involve a set of documentation or steps to follow. This information may include different aspects such as:

  • How to operate
  • How to do a particular calculation
  • How to maintain a particular computer hardware and
  • How to use specific computer software.

On conventional computer architectures, an instruction may also include an opcode which may specify the operation to be performed such as:

  • Add contents of memory to the register
  • Add zero or more operand specifiers and others.

It may also specify literal data, registers or memory locations and even the meanings of the addressing modes, especially in the operand specifiers, which may be in predetermined fields.

With respect to computer hardware, the instructions given to a computer involve how to use the device.

However, these instructions are provided with the device driver.

When a computer receives an instruction, it uses the software or operating system to translate the set of commands into a language that can be understood by the computer.

The software or operating system is however programmed by a human, once again.

The instructions may be of different length or size. It may vary from as little as 4 bits, typically used by the microcontrollers, to many multiples of bytes that are used by the Very Long Instruction Word or VLIW systems.

The VLIW architectures typically include several microcode architectures and therefore can perform multiple operations and operands at the same time.

For this reason, they need several instructions in a single set of commands, which make their instructions so long.

However, as is the case with modern personal computers, mainframe computers and supercomputers, the sizes of the instructions may range anywhere between 16 bits and 64 bits.

There are some instructions that may also have a fixed length. These instructions are used by some specific types of computer architectures, such as the Reduced Instruction

Read Also:  What is Retina Display? Pros, Cons & More

Set Computer or RISC. The size of these particular instructions typically corresponds to the word size of the computer architecture.

What are the Types of Computer Instructions?

The types of computer instructions can be data transfer and manipulation, input and output, and program sequencing and control instructions.

Usually, these are categorized under three major groups or fields such as:

  • The operation code or opcode field – It defines the specific operation to be carried out
  • The address field – It represents the location of the operand and
  • The mode field – It describes how to locate the operand.

Based on the above parameters, there are different types of instruction sets, each with their respective usage. These are:

  • Reduced Instruction Set Computer or RISC that needs only a few cycles per instruction in a simpler form
  • Minimal Instruction Set Computers or MISC that needs basic set of instructions and sub-codes
  • Complex Instruction Set Computer or CISC that needs fewer instructions than RISC
  • Explicitly Parallel Instruction Computing or EPIC that needs instructions to execute them in parallel software
  • Very Long Instruction Word or VLIW that executes instructions in sequence only in the CPU
  • Zero Instruction Set Computer or ZISC that needs instructions with no microinstructions and works on pattern matching comparable to networks of neurons and synapses and
  • One Instruction Set Computer or OISC that is used for structural computing research and teaching computer architecture.

Register and memory stacks also use short and simple instructions to store data instructions in LIFO or Last In First Out pattern to evaluate and backtrack algorithms.

A kind of CPU register called the accumulator also stores intermediate values temporarily used for mathematical and logical calculations with short and simple instructions.

GPR or General Purpose Register stores 8-bit data represented by 6 figures such as B, C, D, H, and L temporarily in the microprocessors.

This set of instructions can also be used for 16-bit operations by combining the general pair of registers such as DE, HL, and BC with short instructions.

What is Instruction with Example?

Examples of computer instructions can be varied and many, and are usually given in 1s and 0s only since that is the only language a computer can understand. It can be an opcode, load or move information bits.

A few typical examples of computer instructions are:

  • ADD − Add two numbers together
  • COMPARE – Compare the numbers
  • IN – Input information from an input device
  • JUMP – Go to the designated RAM address instantly
  • JUMP IF – A conditional instruction for jumping to the selected RAM address and
  • LOAD – Load information from the RAM to the CPU.

Depending on the software or application, the set of instructions may vary. For example, if you are using Logo and want to draw a square, the complete set of instructions will be:

  • forward 100
  • right 90
  • forward 100
  • right 90
  • forward 100
  • right 90
  • forward 100

The examples of instructions may also vary based on their respective formats. For example:

  • Zero Address assembly language instruction – PUSH A, PUSH B etc
  • Zero Address stack transfer operation – TOS <- A, TOS <- B etc
  • One Address assembly language instruction – LOAD C, ADD B, STORE T etc
  • One Address operation register instruction – AC <- M[T], AC <- M[C] etc
  • Two Address assembly language instruction – MOV R1, A; ADD R1, B etc
  • Two Address operation register instruction – R1 <- M[A], R2 <- M[C] etc
  • Three Address assembly language instruction – ADD R1, A, B etc and
  • Three Address operation register instruction – R1 <- M[A] + M[B] etc.

The examples of Memory Reference Instruction format can be OPCODE 000 to 110, Register Reference Instruction format can be OPCODE 111 AND addressing mode I = 0 and Input and Output Instruction format can be OPCODE 111 AND addressing mode I = 1.

There are also a few specific, simpler instructions to store data given to accumulators, memory and register stacks and General Purpose Registers, as mentioned earlier.

Read Also:  Northbridge & Southbridge: 9 Differences

What are the Types of Instruction Format?

There are three formats used for an instruction code for a basic computer namely, memory – reference instruction, register – reference instruction, and input – output instruction.

12 bits of memory are used in memory – reference instruction to denote the address and a single bit to specify the addressing mode I.

Register – reference instruction denotes a test of or an operation on the accumulator register by an op code 111 with the leftmost bit 15 represented by a 0 in the instruction.

The input-output instruction does not need any reference to the memory just like the register-reference instruction.

It is represented by the op code 111 but the leftmost bit is a 1. The other bits are used to denote the type of input output operation or test to be executed.

There are three parts of an instruction format. These are:

  • Addressing Mode – This is the first part that represents the data which can be stored in the CPU register or in the memory
  • Operation Code – This is the second part of the format that gives operation instructions and
  • Operand – This is the third part of the format containing 0 to 3 operands depending on the CPU of the computer and specifies the data or the address of it.

The types of instruction format are:

  • Zero (0) Address Instruction format which has no address field or operand and stacks are used
  • One (1) Address Instruction format which has only one address field and operand is in the accumulator with the other in the memory location along with LOAD and STORE as two special instructions
  • Two (2) Address Instruction format which is most commonly used and has two address fields and two operands and the result can be stored in any location using shorter assembly language and
  • Three (3) Address Instruction format which has three address fields and three operands but needs more bits using a shorter assembly language.

What are Five Types of Instruction Operations?

The five basic types of operations common to several instruction sets are data handling and memory, arithmetic and logic, control flow, coprocessor instructions and number of operands.

The data handling and memory operations include:

  • Setting a register to a set constant value
  • Copying data from a register or a memory location to a memory location or a register and
  • Reading and writing data from hardware devices.

Arithmetic and logic operations include:

  • Adding, subtracting, multiplying, or dividing values of two registers
  • Setting one or more condition codes in the status register
  • Putting the result in the register
  • Incrementing or decrementing in some instruction sets
  • Saving operand fetch
  • Performing bitwise operations
  • Comparing two values and
  • Floating-point instructions.

Control flow operations include:

  • Branching to another location in the program to execute instructions
  • Branching conditionally to another location
  • Branching indirectly to another location and
  • Calling another block of code during saving a location of the subsequent instruction as a point of return.

Coprocessor instruction operations include:

  • Loading or storing data to and from a CPU
  • Exchanging data with CPU registers and
  • Performing coprocessor operations.

Specific machines used different numbers of operands such as:

  • 0-operand for using in zero-address or stack machines
  • 1-operand for using in one-address or accumulator machines
  • 2-operands for using is several CISC and RISC machines
  • 3-operands for reusing data in CISC and RISC machines and
  • More operands for using in some CISC machines that allow using a range of addressing modes.

Sometimes, some complex operations are also performed such as:

  • Moving multiple registers to or from memory at once
  • Transferring large blocks of memory
  • Performing complicated integer and floating-point arithmetic operations
  • SIMD operation on several homogeneous values in parallel
  • Performing atomic operations such as test-and-set or read-modify-write and
  • Performing ALU operations with memory operands instead of operands from a register.

These complex instructions are mainly used as CISC instructions and sometimes may include RISC instruction sets in them.

Read Also:  What is OLED Display? Types, Working Principles & More

What are the Components of Instructions?

The major components of a computer instruction are operands and opcodes which involve the data of the instructions to be carried out and the specific instruction to be performed, respectively.

The opcode helps in identifying the particular operation carried out by the instruction. The operands, on the other hand, contain the elements of operations which include:

  • Registers
  • Data values and
  • Memory addresses.

There can be different types of operands and opcodes which is why the instructions can be of different sizes and occupy diverse bytes in the memory of the computer.

There can be a few specific instruction types that may not come with any operands shown explicitly. In these instructions, the operands are often implied.

What are the Steps in Which an Instruction is Executed?

There are six specific stages in which instructions are executed such as fetch, decode, arithmetic, memory access, register update, and Program Counter or PC update.

In the fetch stage the instruction is fetched from the main memory and current Program Counter and stored in the Instruction Register.

In the decoding stage, the stored instruction in the IR is interpreted.

Arithmetic operation is done by using the Arithmetic Logic Unit by taking in two values as input and giving one as output.

Memory is accessed for only two specific types of instructions such as LOAD and STORE while other instructions skip this stage.

The register file is updated with the output result of the ALU written back. This step is not needed for BRANCH and JUMP instructions.

Finally, the PC is updated at the end of execution of an instruction.

No matter what, computer instructions cannot be executed if they are not complete. It has to have an adequate number of instructions in the following categories:

  • Logical, arithmetic, and shift instructions
  • Moving information instruction to and from processor registers and memory
  • Control instructions of the program
  • Status check instruction of the program and
  • Input and output instructions.

There are few good reasons to say so.

Ideally, the arithmetic, logic and shift commands will offer computational ability to the CPU. Moving instructions to and from processor register and memory is required because a large amount of binary information is held by the memory unit.

However, the actual processing is done in the processor registers. It will not be possible if the ability to move data and information is nil or restricted.

Program control and status checks the necessary instructions for changing the sequence of program execution when needed.

Finally, the input and output instructions are necessary to create an interface between the user and the computer to transfer data to the memory and computational results to the user.

Who Gives Instructions to a Computer?

Technically, the instructions to a computer are given by the input devices attached to the system such as the keyboard, mouse and others.

However, looking at it from a broader aspect, it is actually the humans who give the instructions to the computer through these input devices.

Conclusion

The computer instructions play a very important role in the functioning of the system and carrying out the commands given to it.

Given in a set of codes, these instructions are easily understood by the computer. Usually given by the user through the input devices, instructions are mainly carried out by the processor.