Computer architectures
[CS] Example for Operand
YEJI ⍢
2022. 9. 19. 21:15
728x90
Let's find out about assembly language by solving the example below.
↓↓↓ Question ↓↓↓
Implement the following expression with three-, two-, one-, and zero-operand instruction sequences.
Assume we have ADD and DIV instruction.
Z = (A+B)/C
↓↓↓ Solution ↓↓↓
When 2 address,
Z = A
Z = Z + B
Z = Z/C = (A + B)/C
When 1 address,
AC = A
AC = AC(A) + B
AC = AC(A+B) / C
↓↓↓ Answer ↓↓↓
When 3 address,
ADD Z, A, B
DIV Z, Z, C
When 2 address,
MOV Z, A
ADD Z, B
DIV Z, C
When 1 address,
LOAD A
ADD B
DIV C
STORE Z
When 0 address,
PUSH A
PUSH B
ADD
PUSH C
DIV
POP Z
◡̈