Difference between 3-address and 0-address Instructions


A computer system performs tasks based on 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 0-address instruction, and the important differences between them.

The most fundamental difference between 0-address instruction and 3-address instruction is that the 0-address instruction does not require any operand to perform operations, whereas the 3-address instruction takes three operands to perform operations.

Before discussing the differences between 0-address instruction and 3-address instruction, let us first discuss their basics individually.

What is 0-Address Instruction?

The type of computer instruction that does not take any operand to perform an operation is known as a 0-address instruction. In the case of 0-address instruction, the operands are not specified explicitly in the instruction, instead, the computer instruction identifies the operands implicitly.

This type of computer instructions are primarily used in stack-based computer programming languages. This kind of computer instructions are commonly used to perform simple operations like popping and pushing values ON and OFF of stacks. Although, the 0-address instructions are limiting in terms of types of the operations that they can perform.

Example

The following example illustrate the syntax of 0-address instructions −

PUSH A TOP = 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 0-address instruction and 3-address instruction, let us now discuss the important differences between them.

Difference between 3-Address Instruction and 0-Address Instruction

The following table highlights all the major differences between 3-address instruction and 0-address instruction −

Parameter

3-Address Instruction

0-Address Instruction

Basic

The type of computer instruction that takes three operands to perform operations is referred to as a 3 address instruction.

The type of computer instruction does not require any operand to perform operation is referred to as a 0-address instruction.

Operand

In the case of 3-address instruction, all the three operands are explicitly specified in the instruction.

In the case of 0-address instruction, the instruction implicitly determines the operands.

Complexity

3-address instructions are more complex because they need more information to execute.

0-address instruction are less complex than 3-address instructions.

Readability

3-address instructions are easier to read. This is because, in a 3-address instruction explicitly specified in the instruction.

0-address instructions are less readable due to implicit determination of the operands in the instruction.

Compactness in code

3-address instructions have relatively longer code due to presence of explicit operands.

0-address instructions have compact code due to absence of explicit operands.

Flexibility

3-address instructions can work on any combination of operands, and hence they are more flexible.

0-address instructions are less flexible as they are limited to the current values on the stack.

Suitability

3-address instructions are suitable for optimization by the compiler.

0-address instructions are more suitable for dynamically typed languages.

Language processors

3-address instructions are mainly used in assemblers and compilers.

0-address instructions are mainly used in interpreters.

Processing time

The time required for processing of 3-address instructions is more due to decoding of more information.

The processing time of 0-address instruction is less than that of 3-address instruction.

Memory usage

3-address instructions need more memory space.

0-address instructions consume less memory space than 3-address instructions.

Operations performed

3-address instructions can be used to perform complex operations like arithmetic operations, logical operations, memory operations, etc.

0-address instructions can be used to perform simple operations like popping and pushing values ON and OFF of stacks.

Programming languages

3-address instructions are commonly used in low level programming languages.

0-address instructions are commonly used in high level programming languages.

Uses

3-address instructions are used in such register-based computer architectures.

0-address instructions are used in stack-based computer architectures.

Conclusion

The most significant difference between 0-address instruction and 3-instructions is that the 0 address instructions do not need any operand to execute, while the 3-address instructions require three operands to execute.

Updated on: 21-Apr-2023

152 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements