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
Stuart C. Shapiro
Spring, 2001


Computers

Reading
Barnes, Chapter 1 and Appendix B

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).

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
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!

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 

A byte = a group of 8 bits.
Can represent 256 things/states,
Can represent one instruction, sometimes plus modifications

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

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

Positional notation
Decimal: ones, tens, hundreds, ...
Binary: ones, twos, fours, ...
Octal: ones, eights, sixtyfours, ...
Hexadecimal: ones, sixteens, two hundred fiftysixes, ...

The two binary digits: 0, 1
The eight octal digits: 0, 1, 2, 3, 4, 5, 6, 7
The ten decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
The fifteen hexadecimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f

For conversion:
If divide a number n by a base b, the remainder is the right-most digit, and the result is the rest of the number.
Examples: 3597/10 = 359 R7     11011/2 = 1101 R1

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.

     0000 0000 0110 1111 0000 0000 0111 1010 =
     006f 007a =
     the characters o z
     or the integer 7,274,618
     or a sequence of up to 4 instructions.

Homework 1 is now assigned.

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;}

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

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.

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 by Stuart C. Shapiro. All rights reserved.

Stuart C. Shapiro <shapiro@cse.buffalo.edu>