1 - Computer Science

advertisement
CSCI-235
Micro-Computer in Science
Hardware
Part I
How Computers Represent Data
OFF
ON
OFF
ON
OR
0
= 1 bit
1
= 1 Byte
OR
0
0
1
1
0
1
0
0
= 1 Byte
0
1
0
0
0
0
0
1

Bit (Binary digit) – On or off state of electric current;
considered the basic unit of information; represented by
1s and 0s (binary numbers)

Byte – Eight bits grouped together to represent a
character (an alphabetical letter, a number, or a
punctuation symbol); How many possible combinations?
© Prentice-Hall, Inc
Bit Basics
A



On
© Prentice-Hall, Inc
bit (binary digit)
Is the smallest unit of
information
Can have two values: 1 or 0
Can represent numbers, codes,
or instructions
 Powers
of 2
Bits as Codes

ASCII – American Standard
Code for Information
Interchange

Most widely used code,
represents
each character as a unique
8-bit code
© Prentice-Hall, Inc
Number Systems
 Decimal



number system
Digits (or symbols) allowed: 0-9
Base (or radix): 10
345 is really
3 x 100 + 4 x 10 + 5 x 1
3 x 102 + 4 x 101 + 5 x 100
© Prentice-Hall, Inc
Number Systems (cont’d)
 Binary



number system
Digits (or symbols) allowed: 0, 1
Base (or radix): 2
1001 is really
1 x 23 + 0 x 22 + 0 x 21 + 1 x 20
© Prentice-Hall, Inc
Transforming Between Bases
 Example


Transform 36 (base 10) to base 2
Done in class
© Prentice-Hall, Inc
Decimal to Binary

Decimal number is converted to binary by
repeated divisions by 2



record the remainders
Stop when you reach 0
Concatenate the remainders


The order: first remainder is least significant bit
55d = 110111b
 Counting
in binary
Bits as Instructions
 The
computer stores instructions as
collections of bits. For instance, 01101010
might instruct the computer to add two
numbers
 Other
bit instructions might include where
to find numbers stored in memory or
where to store them
© Prentice-Hall, Inc
Bytes
8 bits = 1 Byte
1024 Bytes = 1 Kilobyte (KB)
1,048,576 Bytes = 1 Megabyte (MB)
1,043,741,824 Bytes = 1 Gigabyte (GB)
1,099,511,627,776 Bytes = 1 Terabyte (TB)
 Kilobyte,
megabyte, gigabyte, and terabyte
are terms that describe large units of data
used in measuring data storage

Example: 20 GB hard drive
© Prentice-Hall, Inc
Inside the System Unit
Motherboard (mainboard) –
Large printed circuit board with
thousands of electrical circuits
 Power supply – Transforms
alternating current (AC) from
wall outlets to direct current
(DC) needed by the computer
 Cooling fan – Keeps the
system unit cool
 Internal Speaker – Used for
beeps when errors are
encountered
 Drive bays – Housing for the
computer’s hard drive, floppy
drive, and CD-ROM / DVDROM drives
© Prentice-Hall,
Inc

The Motherboard

The motherboard
provides the centralized
connection point for the
computer’s components

Most components are
integrated circuits (chips)
• Chips carry electrical current
and contain electronic
switches or transistors
© Prentice-Hall, Inc
The Central Processing Unit:
The Microprocessor
CPU
CPU socket

Central processing unit (CPU) – A
microprocessor that interprets and carries out
instructions given by software. It controls the
computer’s components
© Prentice-Hall, Inc
Components of the CPU

Control unit – Coordinates and controls all parts of
the computer system

Arithmetic-logic unit – Performs arithmetic or logical
operations

Registers – Temporarily store the most frequently
used instructions and data
© Prentice-Hall, Inc
The Control Unit

The control unit manages four basic operations
(fetch, decode, execute, and write-back)


The four-step process is known as the machine
cycle or processing cycle
The processing cycle consists of two phases:
• Instruction Cycle


Fetch – Gets the next program instruction from the
computer’s memory
Decode – Figures out what the program is telling the
computer to do
• Execution Cycle


© Prentice-Hall, Inc
Execute – Performs the requested action
Write-back (Store) – Writes (stores) the results to a register
or to memory
The Arithmetic-Logic Unit
 The
arithmetic-logic unit (ALU) performs
basic arithmetic and logic operations


Adds, subtracts, multiplies, and divides
Compares alphanumeric data
© Prentice-Hall, Inc
What Happens Inside: Unraveling
the Mystery
Instruction
Time
Execution
Time
Execute Instruction
© Prentice-Hall, Inc
Decode Instruction
Place Result in Memory
Fetch Instruction
The Big Picture

A computer with software running on it
 Want to write nice abstract High level Language
(HLL), have stupid computer that only knows how
to execute Machine Language
High-Level Language
C++, Java, etc..

Machine Language
Binary sequences
What is machine language?

Binary sequences interpreted by the computer as
instructions, not very human readable
The Big Picture (cont’d)

To help the situation, introduce assembly
language, a more human readable form of
machine language

Uses MNEUMONICS for the instruction type,
operands
• add A, B




Add is the mneumonic or opcode
A and B are the operands, the variables used in the
instruction
Now we need something to translate assembly
language to machine language  the ASSEMBLER
Lastly, if we had a program that translated HLL
programs into assembly language then we are done,
a COMPILER does this
The Big Picture (cont’d)
HLL
compiler
assembly
language
Least detail
Top level
number = count + 1
add a, b, c
assembler
machine
language
Most detail
Bottom
level
01010010001110010101011010101010
Basic Computer Operation
Memory
CPU
I/O

CPU




Controls the running of programs
Executes instructions
Makes requests of the memory
Memory


Where programs and program variables (i.e., data) are
stored
Handles requests from the CPU
© Prentice-Hall, Inc
Basic Computer Operation (cont’d)

To execute an instruction, the processor must be
able to request 3 things from memory:




Read


Instruction FETCH
Operand (variable) load LOAD
Operand (variable) store STORE
CPU specifies an address and a read operation
memory responds with the contents of the given
address
Write

CPU specifies an address, data to be stored, and a
write operation memory responds by overwriting the
data at the address specified
© Prentice-Hall, Inc
Example
1.
Fetch the next instruction
01010010001110010101011010101010
2.
Figure out what the instruction is (i.e., DECODE IT)
add a, b, c
It is an ADD instruction, this also reveals how many
operands there are
3.
Load operand(s)
Operands are b and c
4.
Do the operation specified by the instruction
ADD b and c together
5.
Store result(s) (if any)
Result goes into variable a
© Prentice-Hall, Inc
INSTRUCTION FETCH AND
EXECUTE CYCLE
1. Fetch the next instruction
2. Update Program Counter (PC)
3. Decode
4. Load operand(s)
5. Do the operation specified by the
instruction
6. Store result(s) (if any)
© Prentice-Hall, Inc
Download