Open In App

Difference between 2-address instruction and 1-address instructions

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

When we convert a High-level language into a low-level language so that a computer can understand the program we require a compiler. The compiler converts programming statements into binary instructions. Instructions are nothing but a group of bits that instruct the computer to perform some operation. An instruction has two fields Opcode and Operand. The opcode field tells what kind of operation we have to perform and the operand field will tell that form which addresses we will get operands to perform the operation.

Now ISA (Instruction Set Architecture) will tell how many instruction is supported by the CPU. Based on operand we have 4 types of address instructions. They will tell in any instruction how much operand information will be given.

  • 0 address instruction
  • 1 address instruction
  • 2 address instruction
  • 3 address instruction

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 another address field for source. 

Two address instruction 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

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. One address instruction 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

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:

2-address instruction 1-address instructions

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.

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.

1-address instructions requires less number of registers compare to 2-address instruction.

2-address instruction are less compact compare to 1-address instruction.

1-address instructions are generally more compact than 2-address instructions, as they have only one memory operand and fewer registers.

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.

1-address instruction are less flexible compare to 2-address instruction.

2-address instruction are slower compare to 1-address instruction.

1-address instructions are generally faster than 2-address instructions, as they require fewer memory accesses and fewer register operations.

It has three fields , one field for opcode and two fields for address. It has only two fields , 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 can’t completely eliminate three memory access. It eliminates two memory access completely.
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.

Conclusion

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.


Next Article

Similar Reads