📌  相关文章
📜  2地址指令和1地址指令的区别

📅  最后修改于: 2021-09-15 01:59:46             🧑  作者: Mango

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

例子:

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

解决方案:

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. 单一地址说明:
单地址指令也是机器指令的一种格式。它只有两个字段。一个用于操作码,另一个用于操作数。

例子:

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

解决方案:

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  

二地址指令和一地址指令的区别:

TWO-ADDRESS INSTRUCTION ONE-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.