Computer Architectural Design
Two approaches to computer architectural design:
- RISC - reduced instruction set computer. Individual instructions
perofrm a single, well-defined operation. RISC approach assumes
that the vast majority of programming will be done in high level
languages. The RISC approach increase the the number of
instructions in assembly but simplifies the structure of the
processor.
- CISC - complex instruction set computer. A single instruction
may perform several operations. It is easier to write assembly
language programs but increase the complexity of the processor.
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 );
- unary operation: goto
- binary operation: copy (x = y), negation (a = -b)
- ternary operation: add-and-store (a = a + b)
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.
- ADD dest, src1, src2: M[dest] = M[src1] + M[src2]
- MULT dest, src1, src2: M[dest] = M[src1] * M[src2]
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.
- ADD dest, src: M[dest] = M[dest] + M[src]
- MULT dest, src: M[dest] = M[dest] * M[src]
- MOVE dest, src: M[dest] = M[src]
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.
- ADD addr: accum = accum + M[addr]
- MULT addr: accum = accum * M[addr]
- LOAD addr: accum = M[addr]
- STORE addr: M[addr] = accum
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.
- ADD: push ( pop + pop )
- MULT: push ( pop + pop )
- PUSH addr: push ( M[addr] )
- POP addr: M[addr] = pop
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