2.1. Types of Computer Architectures

Here we describe the most common Computer Architectures, all of which use stored program control.

2.1.1. The Stack Machine

A stack machine implements a stack with registers. The operands of the ALU are always the top two registers of the stack and the result from the ALU is stored in the top register of the stack.

Examples of the stack machine include Hewlett–Packard RPN calculators and the Java Virtual Machine (JVM).

The advantage of a stack machine is it can shorten the length of instructions since operands are implicit. This was important when memory was expensive (20-30 years ago). Now, in Java, it is important since we want to ship executables (class files) over the network.

../_images/stack_mach.png

2.1.2. The Accumulator Machine

An accumulator machine has special registers, called accumulators, whose contents are combined with another operand as input to the ALU, with the result of the operation replacing the contents of the accumulator.

In order to add two numbers in memory,

  1. place one of the numbers into the accumulator (load operand)
  2. execute the add instruction
  3. store the contents of the accumulator back into memory (store operand)
accumulator = accumulator [op] operand;
../_images/accum_mach.png

2.1.3. The Load/Store Machine

Registers: provide faster access but are expensive.

Memory: provides slower access but is less expensive.

A small amount of high speed memory (expensive), called a register file, is provided for frequently accessed variables and a much larger slower memory (less expensive) is provided for the rest of the program and data. (SPARC: 32 registers at any one time)

This is based on the principle of locality — at a given time, a program typically accesses a small number of variables much more frequently than others.

The machine loads and stores the registers from memory. The arithmetic and logic instructions operate with registers, not main memory, for the location of operands.

Since the machine addresses only a small number of registers, the instruction field to refer to a register (operand) is short; therefore, these machines frequently have instructions with three operands:

add         src1, src2, dest
../_images/load_store_mach.png

Example Machine Instructions

y = y + 10;

For this example, y' is the memory address of y

[y'] means the contents of the memory of y, that the value of y.

Stack Machine Accumulator Machine Load/Store Machine
push [y']
push 10
add
pop y'
load [y']
add 10
store y'
load r0, [y']
load r1, 10
add r0, r1, r2
store r2, y'