The Wayback Machine - https://web.archive.org/web/20230512161403/https://www.geeksforgeeks.org/computer-organization-instruction-formats-zero-one-two-three-address-instruction/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Computer Organization | Instruction Formats (Zero, One, Two and Three Address Instruction)

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Introduction:

In computer organization, instruction formats refer to the way instructions are encoded and represented in machine language. There are several types of instruction formats, including zero, one, two, and three-address instructions. Here is a brief overview of each:

Zero-address instructions: These instructions do not specify any operands or addresses. Instead, they operate on data stored in registers or memory locations implicitly defined by the instruction. For example, a zero-address instruction might simply add the contents of two registers together without specifying the register names.

One-address instructions: These instructions specify one operand or address, which typically refers to a memory location or register. The instruction operates on the contents of that operand, and the result may be stored in the same or a different location. For example, a one-address instruction might load the contents of a memory location into a register.

Two-address instructions: These instructions specify two operands or addresses, which may be memory locations or registers. The instruction operates on the contents of both operands, and the result may be stored in the same or a different location. For example, a two-address instruction might add the contents of two registers together and store the result in one of the registers.

Three-address instructions: These instructions specify three operands or addresses, which may be memory locations or registers. The instruction operates on the contents of all three operands, and the result may be stored in the same or a different location. For example, a three-address instruction might multiply the contents of two registers together and add the contents of a third register, storing the result in a fourth register.

Each type of instruction format has its own advantages and disadvantages in terms of code size, execution time, and flexibility. Modern computer architectures typically use a combination of these formats to provide a balance between simplicity and power.

A computer performs a task based on the instruction provided. Instruction in computers comprises groups called fields. These fields contain different information as for computers everything is in 0 and 1 so each field has different significance based on which a CPU decides what to perform. The most common fields are:

  • Operation field specifies the operation to be performed like addition.
  • Address field which contains the location of the operand, i.e., register or memory location.
  • Mode field which specifies how operand is to be founded.

Instruction is of variable length depending upon the number of addresses it contains. Generally, CPU organization is of three types based on the number of address fields:

  1. Single Accumulator organization
  2. General register organization
  3. Stack organization

In the first organization, the operation is done involving a special register called the accumulator. In second on multiple registers are used for the computation purpose. In the third organization the work on stack basis operation due to which it does not contain any address field. Only a single organization doesn’t need to be applied, a blend of various organizations is mostly what we see generally. 

Based on the number of address, instructions are classified as: 

Note that we will use X = (A+B)*(C+D) expression to showcase the procedure. 

 

  1. Zero Address Instructions – 
     

A stack-based computer does not use the address field in the instruction. To evaluate an expression first it is converted to reverse Polish Notation i.e. Postfix Notation. 

Expression: X = (A+B)*(C+D)
Postfixed : X = AB+CD+*
TOP means top of stack
M[X] is any memory location

 

PUSHATOP = A
PUSHBTOP = B
ADD TOP = A+B
PUSHCTOP = C
PUSHDTOP = D
ADD TOP = C+D
MUL TOP = (C+D)*(A+B)
POPXM[X] = TOP

2 .One Address Instructions – 
This uses an implied ACCUMULATOR register for data manipulation. One operand is in the accumulator and the other is in the register or memory location. Implied means that the CPU already knows that one operand is in the accumulator so there is no need to specify it. 

 

Expression: X = (A+B)*(C+D)
AC is accumulator
M[] is any memory location
M[T] is temporary location
LOADAAC = M[A]
ADDBAC = AC + M[B]
STORETM[T] = AC
LOADCAC = M[C]
ADDDAC = AC + M[D]
MULTAC = AC * M[T]
STOREXM[X] = AC

3.Two Address Instructions – 
This is common in commercial computers. Here two addresses can be specified in the instruction. Unlike earlier in one address instruction, the result was stored in the accumulator, here the result can be stored at different locations rather than just accumulators, but require more number of bit to represent address. 
 

Here destination address can also contain operand. 

Expression: X = (A+B)*(C+D)
R1, R2 are registers
M[] is any memory location
MOVR1, AR1 = M[A]
ADDR1, BR1 = R1 + M[B]
MOVR2, CR2 = C
ADDR2, DR2 = R2 + D
MULR1, R2R1 = R1 * R2
MOVX, R1M[X] = R1

4.Three Address Instructions – 
This has three address field to specify a register or a memory location. Program created are much short in size but number of bits per instruction increase. These instructions make creation of program much easier but it does not mean that program will run much faster because now instruction only contain more information but each micro operation (changing content of register, loading address in address bus etc.) will be performed in one cycle only. 

 

Expression: X = (A+B)*(C+D)
R1, R2 are registers
M[] is any memory location
ADDR1, A, BR1 = M[A] + M[B]
ADDR2, C, DR2 = M[C] + M[D]
MULX, R1, R2M[X] = R1 * R2

Here are some advantages and disadvantages of each instruction format:

Zero-address instructions:

Advantages: 

They are simple and can be executed quickly since they do not require any operand fetching or addressing. They also take up less memory space.

Disadvantages: 

They can be limited in their functionality and do not allow for much flexibility in terms of addressing modes or operand types.

One-address instructions:

Advantages: They allow for a wide range of addressing modes, making them more flexible than zero-address instructions. They also require less memory space than two or three-address instructions.
Disadvantages: They can be slower to execute since they require operand fetching and addressing.

Two-address instructions:

Advantages: They allow for more complex operations and can be more efficient than one-address instructions since they allow for two operands to be processed in a single instruction. They also allow for a wide range of addressing modes.
Disadvantages: They require more memory space than one-address instructions and can be slower to execute since they require operand fetching and addressing.

Three-address instructions:

Advantages: They allow for even more complex operations and can be more efficient than two-address instructions since they allow for three operands to be processed in a single instruction. They also allow for a wide range of addressing modes.
Disadvantages: They require even more memory space than two-address instructions and can be slower to execute since they require operand fetching and addressing.
Overall, the choice of instruction format depends on the specific requirements of the computer architecture and the trade-offs between code size, execution time, and flexibility.


My Personal Notes arrow_drop_up
Last Updated : 19 Apr, 2023
Like Article
Save Article
Similar Reads