📌  相关文章
📜  3地址指令和0地址指令的区别

📅  最后修改于: 2021-09-28 09:29:26             🧑  作者: Mango

先决条件 – 指令格式
1. 三地址指令:
三地址指令是机器指令的一种格式。它有一个操作码和三个地址字段。一个地址字段用于目的地,两个地址字段用于源。

例子:

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

解决方案:

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. 零地址指令:
零地址指令是机器指令的一种格式。它只有一个操作码,没有地址字段。

例子:

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

解决方案:

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 

三地址指令和零地址指令的区别:

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.