Open In App
Related Articles

Difference between 3-address instruction and 2-address instructions

Improve
Improve
Improve
Like Article
Like
Save Article
Save
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. Two-Address Instructions : Two-address instruction is a format of machine instruction. It has one opcode and two address fields. One address field is common and can be used for either destination or source and other address field for source. Example –
X = (A + B) x (C + D) 
Solution:
MOV R1, A      R1 <- M[A]
ADD R1, B      R1 <- R1 + M[B]
MOV R2, C      R2 <- M[C]
ADD R2, D      R2 <- R2 + D
MUL R1, R2     R1 <- R1 x R2
MOV X, R1      M[X] <- R1 
Difference between Three-Address Instruction and Two-Address Instruction :
THREE-ADDRESS INSTRUCTION TWO-ADDRESS INSTRUCTION
It has four fields. It has three fields.
It has one field for opcode and three fields for address. It has one field for opcode and two 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 one address field common for destination and source.
In 3-address format, destination address can not contain operand. While in 2-address format, destination address can have operand.
In 3-address format, instructions are less. While in 2-address format, instructions are more.
It generally requires three memory access. It generally requires two memory access but in some cases it requires three memory access too.
In 3-address format, three memory access is required. While in 2-address format, it eliminated three memory access but not completely.

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