Skip to main content

Machine Instructions and Addressing Modes



Amu_Ke_Fundye


Machine Instructions and

 Addressing Modes


Computer Instruction: A binary code used for specifying micro operations for computer.

Instruction Code: Group of bits used to instruct the CPU to perform specific operation.
  • Instructions are encoded as binary instruction codes.
  • Each instruction code contains of a operation code, or opcode, which designates the overall purpose of the instruction.
  • The number of bits allocated for the opcode determined how many different instructions the architecture supports.

Instruction Set: Collection of instructions.

Instruction Representation: Each instruction has a unique bit pattern, but for human beings a corresponding symbolic representation has been defined.

Instruction Cycles: Instruction cycle consists of following phases
  • Fetching an instruction from memory.
  • Encoding the instruction.
  • Reading the effective address from memory in case of the instruction having an indirect address.
  • Execution of the instruction.

Instruction Format: An instruction consists of bits and these bits are grouped up to make fields.

Some fields in instruction format are as follows
  1. Opcode which tells about the operation to be performed.
  2. Address field designating a memory address or a processor register.
  3. Mode field specifying the way the operand or effective address is determined.

Different types of Instruction Formats

Some common types are as: Three address instruction format, Two address instruction format, One address instruction format, and Zero address instruction format.
  • Three Address Instruction FormatThis system contains three address fields (address of operand1, address of operand2 and address where result needs to be put). The address of next instruction is held in a CPU register called Program Counter (PC).
Bits:  image001
Here, the number of bytes required to encode an instruction is 10 bytes.
Each address requires 24 bit = 3 bytes.
Since, there are three addresses and one opcode field.
Therefore 3 × 3 + 1 = 10 bytes.
The number of memory access required is 7 words.
4 words for instruction fetch, 2 words for operand fetch and 1 word for result to be placed back in memory.
  • Two Address Instruction FormatIn this format, two addresses and an operation field is there. The result is stored in either of the operand address i.e., either in address of first operand or in the address of second operand. CPU register called Program Counter (PC) contains the address of next instruction.
image001
  • One Address Instruction Format: One address field and an operation field. This address is of the first operand. The second operand and the result are stored in a CPU register called Accumulator Register (AR). Since, a machine has only one accumulator, it needs not be explicitly mentioned in the instruction. A CPU register (i.e., Program Counter (PC) holds the address of next instruction. In this scenario, two extra instructions are required to load and store the accumulator contents.
image001
Number of bits required to encode an instruction is 4 bytes. i.e., each address requires 24 bits = 3 bytes. Since, there are one address and one operation code field, 1* 3 + 1= 4 bytes.

The number of memory access required is 3 words i.e., 2 words for instruction fetch +1 word for code for operand fetch.
  • Zero Address Instruction Format: Stack is included in the CPU for performing arithmetic and logic instructions with no addresses. The operands are pushed onto the stack from memory and ALU operations are implicitly performed on the top elements of the stack. The address of the next instruction is held in a CPU register called program counter.
image001
e.g., Add
Top of stack  Top of stack + second top of stack.

Addressing Modes:

The different ways in which the location of an operand is specified in an instruction are referred to as addressing modes.

Types of Addressing Modes

  • Implied Mode: In this mode the operands are specified implicitly in the definition of an instruction.
  • Immediate Mode: In this mode the operand is specified in the instruction itself or we can say that, an immediate mode instruction has an operand rather than an address.
  • Register Mode: In this mode, the operands are in registers.
  • Direct Address Mode: It this mode, the address of the memory location that holds the operand is included in the instruction. The effective address is the address part of the instruction.
  • Indirect Address Mode: In this mode the address field of the instruction gives the address where the effective address is stored in memory.
  • Relative Address Mode: In this mode the content of program counter is added to the address part of the instruction to calculate the effective address.
  • Indexed Address Mode: In this mode, the effective address will be calculated as the addition of the content of index register and the address part of the instruction.

Types of Instructions

  • Data Transfer Instructions: Data transfer instructions cause transfer of data from one location to another without changing the information content. The common transfers may be between memory and processor registers, between processor registers and input/output.
Typical Data Transfer Instructions
image005
  • Data Manipulation Instructions: Data manipulation instructions perform operations on data and provide the computational capabilities for the computer. There are three types of data manipulation instructions: Arithmetic instructions, Logical and bit manipulation instructions, and Shift instructions.

Typical Arithmetic Instructions
image006
Typical Logical and Bit Manipulation Instructions
image007
Typical Shift Instructions
image008

Program Control Instructions

Program control instructions specify conditions for altering the content of the program counter, while data transfer and manipulation instructions specify conditions for data processing operations. The change in value of a program counter as a result of the execution of a program control instruction causes a break in the sequence of instruction execution.

Typical Program Control Instructions
image009

Program Interrupt

The program interrupts are used to handle a variety of problems that arise out of normal program sequence.
  • Program interrupts are used to transfer the program control from a currently running program to another service program as a result of an external or internal generated request. Control returns to the original program after the service program is executed.

Types of Interrupts

There are three major types of interrupts
  1. External interrupt: External interrupts come from Input-Output (I/O) devices or from a timing device.
  2. Internal interrupt: Internal interrupts arise from illegal or erroneous use of an instruction or data. External and internal interrupts from signals that occur in the hardware of the CPU.
  3. Software interrupt: A Software interrupt is initiated by executing an instruction.

Complex Instruction Set Computer (CISC)

  • Computer architecture is described as the design of the instruction set for the processor.
  • The computer with a large number of instructions is classified as a complex instruction set computer. The CISC processors typically have the 100 to 250 instructions.
  • The instructions in a typical CISC processor provide direct manipulation of operands residing in memory.
  • As more instructions and addressing modes are incorporated into a computer, the more hardware logic is needed to implement and support them and this may cause the computations to slow down.

Reduced Instruction Set Computer (RISC)

  • RISC architecture is used to reduce the execution time by simplifying the instruction set of the computer.
  • In the RISC processors, there are relatively few instructions and few addressing modes. In RISC processors, all operations are done within the registers of the CPU.
Regards 
Amrut Jagdish Gupta

Comments

Popular posts from this blog

Undecidability

Amu_Ke_Fundye Undecidability Decidable Problem If there is a Turing machine that decides the problem, called as Decidable problem. A decision problem that can be solved by an algorithm that halts on all inputs in a finite number of steps. A problem is decidable, if there is an algorithm that can answer either yes or no. A language for which membership can be decided by an algorithm that halts on all inputs in a finite number of steps. Decidable problem is also called as totally decidable problem, algorithmically solvable, recursively solvable. Undecidable Problem A problem that cannot be solved for all cases by any algorithm whatsoever. Equivalent Language cannot be recognized by a Turing machine that halts for all inputs. The following problems are undecidable problems: Halting Problem:  A halting problem is undecidable problem. There is no general method or algorithm which can solve the halting problem for all possible inputs. Emptyness Problem:...

ALU and Data Path

Amu_Ke_Fundye ALU and Data Path The CPU can be divided into a data section and a control section. The   data section , which is also called the   datapath. Datapath The registers, the ALU, and the interconnecting bus are collectively referred to as the datapath.  Each bit in datapath is functionally identical.  The datapath is capable of performing certain operations on data items. The  control section  is basically the  control unit ,  which issues control signals to the datapath . Bus : A Bus is a collection of wires or distinct lines meant to carry data, address and control information. Data Bus : it is used for transmission of data. The number of data lines corresponds to the number of bits in a word. Address Bus : it carries the address of the main memory location from where the data can be accessed. Control Bus : it is used to indicate the direction of data transfer and to coordinate the timing of ...

Funny Shortcut to Remember Periodic Table

Amu_Ke_Fundye Funny Shortcut to Remember Periodic Table THE PERIODIC TABLE The periodic table is a tabular display of the chemical elements, organized on the basis of their atomic number's , electron configurations, and chemical properties.In order to appreciate the general trends in chemistry and to explain the deviations of some from these general trends we need to to have good knowledge about the position of those elements in periodic table. This knowledge is also extremely important for competitive exams. So, here I present a way to memorize this using some funny easy shortcut sentences. THE FIRST 18 ELEMENTS (H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar)  H ie  He   Li es  Be cause  B oron  C an N ot  O xide  Fl orine.. N e w  Na tions  M ight  Al so  Si ng  P eaceful  S ong  Cl early  A gain  THE ...