The Department of Computer Science & Engineering
|
|
STUART C. SHAPIRO: CSE
115 C
|
Assume we are using a binary, digital, serial, electronic, stored-program computer.
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).
| With | 1 | bit | we can represent | 2 | things/states |
| 2 | bits | 4 | |||
| 3 | 8 | ||||
| 4 | 16 | ||||
| n | 2n |
Using bits to represent integers:
| Binary | Decimal |
| 000 | 0 |
| 001 | 1 |
| 010 | 2 |
| 011 | 3 |
| 100 | 4 |
| 101 | 5 |
| 110 | 6 |
| 111 | 7 |
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.
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.
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