Computer Architectural Design

Two approaches to computer architectural design:

Operations

We specify that each statement should perform a single operation. Complex operations are done as a sequence of simple operations. For example the assignment statement:
    a = (b * c ) % (d + f );
The addition is a binary operation. It needs two source operands and a destination operand to store the result. In our discussion we will use addresses to specify operands. We can classify machines on how many addresses we need to perform common arithmetic operations: 3-address, 2-address, 1-address, and 0-address.

3-Address Machine

All three operands are explicit in each instruction.

2-Address Machine

In a 2-address machine instructions only have two explicit addresses. One address doubles as the address of a source operand and the address of the destination.

1-Address Machine (Accumulator)

In the 1-address machine or accumulator, the accumulator doubles as the destination and one of the source operands. One needs to specify only the address of the other source operand. In the STORE instruction however, the accumulator is the source operand and the explicit operand is the destination. In an accumulator machine, the accumulator is the register. The accumulator is internal to the CPU.
Show how you can use the instructions above to evaluate the statement
a = a * b + c * d * e. You should assume that the variables a, b, c, d, and
e are associated with the memory locations 100, 104, 108, 112, and 116,
respectively.

LOAD  100                     ; acc = a
MULT  104                     ; acc *= b
STORE 100                     ; a = acc
LOAD  108                     ; acc = c
MULT  112                     ; acc *= d
MULT  116                     ; acc *= e
ADD   100                     ; acc += a
STORE 100                     ; a = acc

0-Address Machine (Stack Machine)

All we need to know where to find both the operands and where to store the result. Operations take values from the stack and push their results back onto the stack. We need two special operations PUSH and POP to transfer values between memory cells and the stack. A small part of the stack is internal to the CPU; the remaining values are in memory. The number values on the stack, or stack depth, can influence the execution time of programs.
Show how you can use the instructions above to evaluate the statement
a = a * b + c * d * e. You should assume that the variables a, b, c, d, and
e are associated with the memory locations 100, 104, 108, 112, and 116,
respectively.

PUSH 100                 ; a
PUSH 104                 ; a  b
MULT                     ; (a * b)
PUSH 108                 ; (a * b)  c
PUSH 112                 ; (a * b)  c  d
MULT                     ; (a * b)  (c * d)
PUSH 116                 ; (a * b)  (c * d)  e
MULT                     ; (a * b)  (c * d * e)
ADD                      ; (a * b + c * d * e)
POP 100