Open In App
Related Articles

Difference between 2-address instruction and 1-address instructions

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

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

In computer architecture and assembly language programming, 2-address and 1-address instructions refer to the number of memory operands or memory locations accessed by the instruction. Here are the key differences between 2-address and 1-address instructions:

Number of memory operands: A 2-address instruction involves two memory operands: one source operand and one destination operand. In contrast, a 1-address instruction involves only one memory operand: the operand that is the source or destination of the instruction.

  1. Use of registers: 2-address instructions typically require more registers than 1-address instructions. This is because 2-address instructions have both a source and destination operand, which may require additional registers to hold intermediate values or to perform calculations.
  2. Code size: 1-address instructions are generally more compact than 2-address instructions, as they require only one memory operand and fewer registers.
  3. Flexibility: 2-address instructions are more flexible than 1-address instructions, as they allow for more complex calculations and expressions to be performed. This is because 2-address instructions have both a source and destination operand, which can be used to hold intermediate values or to perform calculations.
  4. Execution time: 1-address instructions are generally faster than 2-address instructions, as they require fewer memory accesses and fewer register operations.

In summary, 2-address instructions are more flexible and powerful but require more memory operands and registers, while 1-address instructions are more compact and faster but offer less flexibility. The choice of instruction format depends on the specific requirements of the program, the hardware architecture, and the tradeoffs between code size, execution time, and flexibility.

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 

2. One-Address Instructions : One-Address instruction is also a format of machine instruction. It has only two fields. One for opcode and other for operand. Example:

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

Solution:

LOAD A      AC <- M[A]
ADD B       AC <- AC + M[B]
STORE T     M[T] <- AC
LOAD C      AC <- M[C]
ADD D       AC <- AC + M[D]
MUL T       AC <- AC x M[T]
STORE X     M[X] <- AC  

Difference between Two-Address Instruction and One-Address Instruction :

TWO-ADDRESS INSTRUCTIONONE-ADDRESS INSTRUCTION
It has three fields.It has only two fields.
It has one field for opcode and two fields for address.It has one field for opcode and one field for address.
It has long instruction length as compared to one-address.While it has shorter instruction length.
It is slower accessing location inside processor than memory.It is faster accessing location inside processor than memory.
It generally needs two memory accesses.It generally needs one memory accesses.
There may be three memory accesses needed for an instruction.There is a single memory access needed for an instruction.
It can’t completely eliminate three memory access.It eliminates two memory access completely.

Last Updated : 19 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads