Homework # 3 Karimah Najiyah 1206202305
Homework # 3 Karimah Najiyah 1206202305
1. Develop a program for a stack machine (zero address machine/instruction), to solve an equation X = (A2 + B) - (C/(D x E2)). A,B,C,D dan E are variables, located in memory (integers). The available instructions are : PUSH M and POP M (M is a variabel), ADD, SUB, MUL and DIV. Answer: 1. PUSH A 2. PUSH A 3. MUL 4. PUSH B 5. ADD 6. PUSH C 7. PUSH D 8. PUSH E 9. PUSH E 10. MUL 11. MUL 12. DIV 13. SUB 14. POP X 2. Also develop a program to solve the same equation as in problem number 1, for one address machine/instruction. The available instructions are : LOAD M, STORE M, ADD M, SUB M, MUL M dan DIV M ; where M is a variable located in Main Memory. Answer : Instruction LOAD E MUL E MUL D STORE X LOAD C DIV X STORE X LOAD A MUL A ADD B SUB X STORE X Comments AC AC AC X AC AC X AC AC AC AC X
3. Say that we have memory state (address and its content) as the following : Word 20 contains 40. Word 30 contains 50. Word 40 contains 60 and Word 50 contains 70. If we have one-address machine with an accumulator, determine the content of the accumulator after the executios of the following instructions : a. LOAD IMMEDIATE 40 ? b. LOAD DIRECT 50 ? c. LOAD INDIRECT 30 ? d. LOAD DIRECT 40 ? e. LOAD DIRECT 20 ? f. LOAD INDIRECT 20 ? Answer : a. LOAD #40 b. LOAD 50 c. LOAD @30 d. LOAD 40 e. LOAD 20 f. LOAD @20 ACC=40 ACC=70 ACC=70 ACC=60 ACC=40 ACC=60