You are on page 1of 24

CIS 450

Basics of Computer Architectures

A Brief History

1939 - HARVARD MARK I 1943 - COLOSSUS 1943 Work begins on the ENIAC

first true general purpose computer

1945 Von Neumann writes First Draft of a report to the EDVAC

Von Neumans Criteria


A computer must have the following attributes 1. An addressable memory containing both data and instructions. Allows data and instructions to be read and written to in any desired order 2. A calculating unit (Arithmetic Logic Unit) capable of performing both arithmetic and logical operations on the data. 3. A control unit (program counter), which could interpret an instruction retrieved from the memory and select alternative courses of action based on the results of previous operations.

Fetch-Execute Cycle
The computer operates the following loop for each program
pc= 0; do { instruction = memory[pc++]; decode( instruction ); fetch( operands ); execute; store( results ); } while( instruction != halt );

Note: instructions (=verb) and operand (= object)

Terms

CPU Central processing unit The engine of the computer that executes programs. ALU Arithmetic logic unit This is the part of the CPU that executes individual instructions involving data (operands). Register A memory location in the CPU which holds a fixed amount of data. Registers of most current systems hold 32 bits or 4 bytes of data. PC Program counter, also called the instruction pointer, is a register which holds the memory address of the next instruction to be executed. IR Instruction register A register which holds the current instruction being executed. Acc Accumulator A register designated to hold the result of an operation performed by the ALU. Register File A collection of several registers.

Fundamental Computer Architectures

Stack Machines Accumulator Machines Load/Store (Register-Register) Machines

Stack Machines

Stack implemented with registers Operands to the ALU are always the top two registers

Push loads memory into 1st register (top of stack), moves other regs down Pop does the reverse.

Example: Add combines contents of first two registers, moves rest up. Results from ALU are stored in the top register of the stack

Stack Machines

Examples: HP RPN Calculators and the Java VM

Accumulator Machines

An accumulator machine has a special register, called an accumulator, whose contents are combined with another operand as input to the ALU, with the result of the operation replacing the contents of the accumulator.
accumulator = accumulator [op] operand;

In fact, many machines have more than one accumulator

Accumulator Machines

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)

Load/Store Machines

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.

Load/Store Machines

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.
These machines frequently have instructions with three operands: add src1, src2, dest

Example Machine Instruction Sets


y = y + 10; y &y [y] *y = *&y = y

Stack Machine push [y] push 10 add pop y

Accumulator Machine load [y] add 10 store y

Load/Store Machine load r0, [y] load r1, 10 add r0, r1, r2 store r2, y

Machine Instructions

Machine instructions are classified into the following three categories:


1.

2.

3.

data transfer operations (memory register, register register) arithmetic logic operations (add, sub, and, or, xor, shift, etc) program control operations (branch, call, interrupt)

How the operands are specified is called the addressing mode. We will discuss addressing modes more later.

The Computers Software

The program instructions are stored in memory in machine code or machine language format. An assembler is the program used to translate symbolic programs (assembly language) into machine language programs.

The Computers Software

machine language Low level computer instructions that are encoded into binary words. assembly language The lowest level human readable programming language. All of the detailed instructions for the computer are listed. Assembly programs are directly encoded into machine code. Assembly code can be written by humans, but is more typically produced by a compiler. high level language Humans typically write programs in a language which allows program logic to be expressed at a conceptual level, ignoring the implementation details which are required of assembly language programs.

Compilation Steps
file.c
compile Note: preprocessor modifies source code before compiling begins

file.s
assemble Creation of object file - combination of machine instructions, data, and information needed to place instructions properly in memory

file.o
linker Merges object files and creates executable

a.out

The Assembler

Initially compilers were inefficient producing code that was not optimized for speed or memory usage Hardware efficiency was extracted at the expense of the programmers time

If a fast program was desired, it was either hand assembled or the compiled code was hand optimized

The Assembler

Compilers have improved to the point where they equal or rival code produced by hand

Even poorly optimized code run relatively fast on todays computers

So why study assembly language?

Why Study Assembly?


1.

2. 3.

4.

To understand or work on an operating system. To understand or work on a compiler. Useful when working on real-time or embedded systems To understand the internal workings of a computer.