Open In App

Difference between 3-address instruction and 0-address instruction

Last Updated : 16 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

According to how many addresses an instruction consumes for arguments, instructions can be grouped. Two numerous kinds of instructions are 3 address and 0 address instructions. It is crucial to comprehend the distinction between these two, in order to know how different processors function in relation to data processing. By the end of this article, readers will learn what 3-address and 0-address instructions are, their strengths and weaknesses, and when to use which instruction variant.

What is Three-Address Instructions?

Three-address instruction is a format of machine instruction. It has one opcode and three address fields. One address field is used for destination and two address fields for source.

Example:

X = (A + B) x (C + D)

Solution:

ADD R1, A, B R1 <- M[A] + M[B] ADD R2, C, D R2 <- M[C] + M[D] MUL X, R1, R2 M[X] <- R1 x R2

Advantages of Three-Address Instructions

  • Simplifying memory access, as it incurs few instructions if direct memory access is used to perform challenging calculations.
  • Better performance because the complex operation to be performed has a fewer instruction count.

Disadvantages of Three-Address Instructions

  • Uses more instruction memory space due to the fact that all instructions must provide for three addresses.
  • This is because it involves more complicated instruction decoding because there is more than one address to be handled.

What is Zero-Address Instructions?

Zero-address instruction is a format of machine instruction. It has one opcode and no address fields.

Example:

X = (A + B) x (C + D)

Solution:

LOAD A AC <- M[A] PUSH A TOS <- A PUSH B TOS <- B ADD TOS <- (A + B) PUSH C TOS <- C PUSH D TOS <- D ADD TOS <- (C + D) MUL TOS <- (C + D) x (A + B) POP X M[X] <- TOS

Advantages of Zero-Address Instructions

  • It is less complex than other forms of instruction since all the addresses do not have to be detailed and it uses less memory.
  • Lean for the stack-based compute environments such as virtual machines.

Disadvantages of Zero-Address Instructions

  • Low flexibility because all the operations that are done have to be based on the stack model.
  • can give an overall impression of a lower Overall instructions of the processor, for complex operations as may see lead to inefficiency.

Difference between Three-Address Instruction and Zero-Address Instruction

THREE-ADDRESS INSTRUCTIONZERO-ADDRESS INSTRUCTION
It has four fields.It has only one field.
It has one field for opcode and three fields for address.It has one field for opcode and no fields for address.
It has long instruction length.It has shorter instruction.
It is slower accessing location inside processor than memory.It is faster accessing location inside processor than memory.
There is distinct address fields for destination and source.There is no address field common for destination and source.
In 3-address format, destination address can not contain operand.While in 0-address format, there is no field for operand.
In 3-address format, number of instructions are less.While in 0-address format, number of instructions are more.
It may need three memory accesses for one instruction.It does not need three memory accesses.

Conclusion

Operand access is significantly the only major distinguishing factor between three-address and zero-address instructions. Whereas 3-address instructions enable direct manipulation of locations in the memory, 0-address instructions work on the basis of a stack. Both has its pros and cons, and which one to use, depends on the architecture and computational load of the system being developed.


Next Article

Similar Reads