Difference between 3-address and 2-address Instructions


A computer system performs operations as per the instruction provided to it. These computer instructions are written in different formats based on the number of addresses that they contain. In this article, we will discuss the two types of computer instructions namely, 3-address instruction and 2-address instruction, and the important differences between them.

The fundamental difference between 3-address instruction and 2-address instruction is that the 3-address instruction requires three operands, while the 2-address instruction requires two operands to execute.

Before discussing the differences, let us first know a bit about 3-address and 2-address instructions individually. So, let gets started with the introduction of 2-address instruction.

What is a 2-Address Instruction?

The type of instruction in a computer system that requires minimum two operands to perform operations is known as a 2-address instruction. In the case of 2-address instruction, the result is stored in one of the two operands.

In other words, a computer instruction in which operations like addition, subtraction, multiplication, etc. are performed on two values stored in registers and the result is also stored back into one of the same registers, it is called a 2-address instruction.

The 2-address instruction is very common in commercial computer systems.

Syntax

The following is the syntax of the 2-address instruction −

A B, C

Where, A is the opcode for example "ADD" for addition, B is the source operand, and C is the destination operand. Here, the destination operand is used to store result, and hence it can be a register or a memory location.

Example

The following is an example to illustrate the 2-address instruction −

ADD A, B A = A + B

Here, contents of the register A and register B will be added and the result will be stored in the register A.

What is 3-Address Instruction?

The type of computer instruction that takes three operands to perform tasks is called a 3-address instruction. In the case of 3-address instruction, all the three operands on which it performs operations are specified in the instruction explicitly. Therefore, these computer instructions are more flexible than 0-address, 1-address, and 2-address instructions. However, they are relatively more complex in terms of operations that they perform.

In a 3-address instruction, the operands represent the followings −

  • The first operand denotes the destination operand.

  • The second and third operands denote the source operands.

The 3-address instructions are widely used to perform various operations such as arithmetic operations, logical operations, memory operations, etc.

Example

The following example illustrate the syntax of a 3-address instruction −

ADD A, B, C

Here, A is the destination operand, and B and C represent the source operands.

After discussing the basics of 1-address instruction and 3-address instruction, let us now discuss all the significant differences between them.

Difference between 3-Address Instruction and 2-Address Instruction

The following table highlights all the significant differences between 3-address instructions and 2-address instructions −

Parameter

3-Address Instruction

2-Address Instruction

Basic

A type of computer instruction that takes three operands is known as 3-address instruction.

A type of computer instruction that takes two operands is known as 2-address instruction.

Number operands required

3-address instructions require three operands to execute.

2-address instructions require two operands to execute.

Registers

3-address instructions use more number of registers.

2-address instructions use less number of registers as compared to 3-address instructions.

Code length

3-address instructions are longer as they have more number of operands.

1-address instructions are shorter than 3-address instructions.

Decoding time

3-address instructions take more time to decode due to their complex instruction format.

2-address instructions take less time to decode due to their simple instruction format.

Memory usage

3-address instructions consume more memory space due to their longer size.

2-address instructions consume comparatively less memory space due to their smaller size.

Execution time

3-address instructions take more time to execute.

2-address instructions take less time to execute as compared to 3-address instructions.

Complexity

3-address instructions are more complex because they use more operands.

2-address instructions are less complex than 3-address instructions.

Flexibility

3-address instructions are more flexible as they can be used to perform more number of operations.

2-address instructions are less flexible than 3-address instruction as they can perform limited operations.

Ease of programming

3-address instructions are relatively easier to program because of their high flexibility.

2-address instructions are slightly complex to program due to less flexibility.

Addressing modes

3-address instructions support various types of addressing modes like direct, indirect, and immediate addressing modes.

2-address instructions support register addressing modes only.

Conclusion

In conclusion, the most significant difference between 3-address instruction and 2-address instruction is in the number operands required, i.e. a 3-address instruction requires three operands to execute, while a 2-address instruction requires two operands to execute.

Updated on: 21-Apr-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements