Open In App

Difference between 3-address instruction and 0-address instruction

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

Prerequisite – Instruction Formats
1. 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 

2. 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 



Difference between Three-Address Instruction and Zero-Address Instruction :

THREE-ADDRESS INSTRUCTION ZERO-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.


Last Updated : 16 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads