August
1997 QUESTION 4 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
4. | (a) Write programs to compute | [8] | |||||||||||||||||||||||||||||
X := (( A + B ) / ( C - D )) + ( E * F ) | |||||||||||||||||||||||||||||||
for 3-address and 1-address
machines with instructions sets as follows:
|
|||||||||||||||||||||||||||||||
Good answers are : | |||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||
Award up to [4] per program. Full marks if the program delivers the correct value into X. Deduct [1] for failing to write answer to X, Deduct [1] for each sub-expression that is wrongly evaluated. | |||||||||||||||||||||||||||||||
(b) Suppose that the instructions shown above are the only instructions available on these machines, and suppose that all addresses/operands are 4 bits. What is the minimum size for the instructions of each of the two machines? | [4] | ||||||||||||||||||||||||||||||
3-address: 4 instructions, which is 22. Therefore 2 bits needed for op code field; | [1] | ||||||||||||||||||||||||||||||
3 * $ bits for address + 2 for opcode = 14. | [1] | ||||||||||||||||||||||||||||||
1-address: 6 instructions, therefore need up to 23 opcodes; 3 bits needed; | [1] | ||||||||||||||||||||||||||||||
4 bits for address + 3 opcode = 7. | [1] | ||||||||||||||||||||||||||||||
(c) Use your answer to part (b) to calculate which of your two programs will occupy more storage space (in bits). Would the answer be different if addresses were 32 bits? | [4] | ||||||||||||||||||||||||||||||
Any reasonable 3-address program will have five instructions, and will therefore need 5 * 14 = 90 bits. | [1] | ||||||||||||||||||||||||||||||
The storage for the 1-address program will depend on the number of instructions used: 11 instructions: 77 bits, 12 instructions: 84 bits; 13 instructions: 91 bits; 14 instructions 98 bits. | [1] | ||||||||||||||||||||||||||||||
Therefore, the 3-address program occupies less space. | |||||||||||||||||||||||||||||||
Corresponding answers for 32-bit addresses, 3-address: 490 bits; 1-address, 11 instructions: 385 12 instructions: 420 13 instructions: 455 14 instructions: 490. | [1] | ||||||||||||||||||||||||||||||
Therefore the answer will usually be different for the 32-bit addresses. | [1] | ||||||||||||||||||||||||||||||
Allow consequential marks throughout this question. | |||||||||||||||||||||||||||||||
(d) Which component within the CPU is used to process instructions such as ADD, SUB, MUL etc.? Give two other instructions which might also be processed by this component. | [4] | ||||||||||||||||||||||||||||||
The arithmetic logic unit | [2] | ||||||||||||||||||||||||||||||
Any boolean instructions, | [2] | ||||||||||||||||||||||||||||||
e.g. and, or, not, etc. |