The Department of Computer Science & Engineering
cse@buffalo
STUART C. SHAPIRO: CSE 115 C

CSE 115
Introduction To Computer Science for Majors I
Lecture C
Lecture Notes #3
Stuart C. Shapiro
Spring, 2007


Computers

Equivalence of Computers
Whether a computer is analog or digital, serial or parallel, built from vacuum tubes, solid-state micro-chips, or optical fibers, it can do the same things (modulo instruction sets and number of processors).

Assume we are using a binary, digital, serial, electronic, stored-program computer.

What is a computer?
A computer is a general-purpose procedure follower.

Hardware
Central Processing Unit (CPU)
Random Access Memory (RAM)
Read Only Memory (ROM)
Disk Drives
Screen
Keyboard
Mouse

Software
Operating System
Window Manager
IDEs
Compilers
Interpreters
Applications

A View of RAM
A linear arrangement of addressable groups of binary switches.

Set the switches, turn it on, it does something!
Compare to home circuit breakers and main power switch.

Labels of a two-position switch might be
     on & off
     up & down
     open & closed
     1 & 0
It's all a matter of interpretation.
We'll use 1 & 0, and call the switch a binary digit (bit).

With1bitwe can represent2things/states
 2bits 4 
 3  8 
 4  16 
 n  2n 

Using bits to represent integers:
BinaryDecimal
0000
0011
0102
0113
1004
1015
1106
1117

A byte = 8 bits, 2 hexadecimal digits.
Can represent 256 things/states,
or count from 0 to 255.

Integers are represented using 4 bytes.

Representing characters:
There are 26 letters in English---need 5 bits.
For upper and lower case, 52 characters---need 6 bits.
Including digits and special characters, 94 characters on keyboard---need 7 bits.
Unicode: Representation all characters of all languages---use 2 bytes per character.

Great Idea: Stored Program concept (John von Neumann, 1945)
The same medium can store program and data.
Programs can be treated as data.

A byte can represent one instruction, sometimes plus modifications
A group of bytes can represent an address in RAM.

CPU
The CPU can execute instructions, which include loading data from RAM into active registers, and writing data to RAM.

Program Counter (PC) contains the address, in RAM, of the next instruction.

The Fetch Execute Cycle (a procedure in pseudocode)

     Repeat forever {
       Fetch instruction at PC;
       Increment PC;
       Execute the fetched instruction;}

Note: Program = fetched data.

Program Translation
Machine Languages: actual switch/bit settings.

Assembly Languages: Symbolic instructions, translated into machine language by assemblers.

High/Compiler Level Languages: Problem-oriented; translated into assembly language by compilers.

Interpreted Languages: A program reads the source code, and does the appropriate things.

Java: The Java compiler translates Java source into bytecode = machine language for the Java Virtual Machine (JVM). Bytecode then interpreted by bytecode interpreter.

Compile Time vs. Run Time

Types of Programming Languages
Imperative Languages (C, Basic, Fortran, Pascal, Java):
     define absval(x) {
       if x < 0 then return -x;
       else return x;}
Functional Languages (Lisp, ML):
     (define absval (x)
        (if (< x 0) then (- x)
         else x)))
Logical Languages (Prolog):
     absval(X, Y) :- X < 0, Y is -X.
     absval(X, Y) :- X >= 0, Y is X.

Procedural Languages (C, Basic, Fortran, Pascal):
Focus is on procedures that operate on objects.

Object-Oriented Languages (C++, Java):
Focus is on objects that have behaviors.

Java is an imperative, object-oriented, compiler-level language.

First Previous Next

Copyright © 2001, 2007 by Stuart C. Shapiro. All rights reserved.

Last modified: Thu Sep 6 20:21:29 EDT 2007
Stuart C. Shapiro <shapiro@cse.buffalo.edu>