Computer Architecture

Download Report

Transcript Computer Architecture

Introduction to Computing
Unit 2 : Computer Architecture
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Summary of the Lecture
• Data representation
• What’s inside
- The processor
- Memory
• The machine cycle
• Input/output
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Digital Computing
• Nowadays all computers are digital
• They deal with two-state, on-off data
- 0/1
- yes/no
- true/false
• This simplifies how they are made
• More reliable, cheaper, quicker
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Digital Computers
Most information can be coded into digital
signals.
Text
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras risus. Pellentesque
et libero. Integer rhoncus lacinia tellus. Integer ac dui a risus tristique
ullamcorper. Sed suscipit dui vel elit. Vestibulum eros. Nulla accumsan laoreet
lectus. Integer metus. Cum sociis natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus.
Dates, numbers, contact details, email addresses
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Digital Computers
Most information can be coded into digital signals.
Music
Images
V1.0
Program instructions
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
File Data Types
If you look at the files on your storage medium, you will
see a wide range of different types of data:
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bits and Bytes
• A bit is the smallest unit of data
• It is 0 or 1 – nothing else
• Collections of bits can mean anything
e.g. “can you come out tonight?”
- 11=yes, 10=maybe, 01=if you pay, 00=no
• More bits and you can say more
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bits and Bytes
• With enough bits you can say anything but
you might need a lot of bits, so we usually
group them
8 bits = 1 byte
• 1 byte is how much is stored in one location
in most computers
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bits and Bytes
1 byte is not a lot
• 01101011
There are 256 (28) different ways of arranging
the 8 bits in a byte:
• 00000000
to
• 11111111
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bits and Bytes
256 combinations can give you:
• 256 different whole numbers (0-255)
• 256 different characters:
-
V1.0
Enough for A-Z, a-z plus a few more)
Not enough for all the languages in the world
We need more bytes for that
But with enough bytes, anything is possible
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Lots of Bytes
•
•
•
•
•
1024 bytes is 1 kilobyte
1024 kilobytes is 1 megabyte
1024 megabytes is 1 gigabyte
1024 gigabytes is 1 terabyte
1024 terabytes is 1 petabyte
and so it goes on – we always want more!
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bytes are Versatile
Bytes can be integers:
• 00000001 =1
• 00000010=2
• 00000011=3
• 00000100=4
• 00000101=5
• 00000110=6
• 00000111=7
etc.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bytes and Integers
128
64
32
16
8
4
2
1
Each column is worth twice the column to its right
128
64
32
16
8
4
2
1
0
0
0
0
0
0
1
0
Add up the values that have a 1 in them, in this case it is 2
128
64
32
16
8
4
2
1
1
0
0
0
1
1
1
1
In this case, it is 128+8+4+2+1=143
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
More Uses of Bytes
• We can make codes
- 01000001=65
- We can say that means “A”
- 1000010=66
- That means “B”
• We can now write text
• This particular code is called ASCII – American
Standard Code for Information Interchange.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Bytes do not always mean the
same thing
• So how do we know if 1000001 is 65 or “A”?
• It all depends on the software.
• We can say that it depends on where it is in
memory (the address). For example, it could be:
V1.0
Address
0-100
101-200
201-300
301-400
401-500
Content
instructions
numbers
letters
other data
spare
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
It all depends
The software determines what the bytes mean:
•
•
•
•
•
•
V1.0
Integers
Fractional numbers
Text
Images
Sound
Program instructions
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Number Systems
• We are used to thinking in tens but it
doesn’t have to be like that.
• Binary is simpler.
- Only two digits 0 and 1
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Number Systems
Decimal: based on 10. 10 digits 0-9. Each column is
worth 10 times the one on the right
1000
100
10
1
Binary: based on 2. 2 digits 0-1. Each column is worth
2 times the one on the right
8
V1.0
4
2
1
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Number Systems
• The trouble with binary is that you need a
lot of digits for not a lot of information
but
• It is convenient for computers
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Number Systems
There is a another way:
• Hexadecimal otherwise known as hex
-
4096
V1.0
Based on the number 16
16 digits
0123456789ABCDEF
Each column is worth 16x the one on the right
256
16
1
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Hexadecimal (Hex)
4096
256
16
1
0
0
1
1
(16 *1) + 1 = 17
4096
256
16
1
0
0
A
6
(A (that’s 10) * 16) + 6 = 166
4096
256
16
1
0
0
F
F
(F * 16) + F = (15 * 16) + 15 = 255
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Hexadecimal
So…..
• hexadecimal is shorthand for binary
• 1 hex digit is worth 4 binary digits
• F = 1111 = 15
hex
V1.0
binary
decimal
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Arithmetic
• Adding binary numbers is easy.
• There are 4 rules:
• 0+0=0
• 0+1=1
• 1 + 1 = 0, carry 1
• 1 + 1 + 1 = 1, carry 1
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Arithmetic
Add 0110 + 0011
That is 6 + 3 = 9 in decimal
0110
0011
1001
carry→
1 1
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Arithmetic
Subtraction is carried out by changing the
number being subtracted into a negative, then
adding.
• 5 - 4 = 1 is the same as
• 5 + (-4) = 1
Negative numbers can be made in binary by
using one of the bits to represent a sign.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Integers and Floating Point
Integers are whole numbers.
• 1 byte can hold integers from 0 to 255.
For larger numbers or fractions, we need
another method – floating point.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Floating Point Numbers
• The number is split into two parts:
- The mantissa is the fractional part.
- The exponent is a measure of the size of the
number.
• Floating point numbers can represent very large
and very small numbers in a limited amount of
memory.
• The numbers are usually approximated.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Floating point numbers
In decimal:
1.456
mantissa
E4
exponent
This is a shorthand way of saying:
14560
(move the point 4 places to the right)
It’s the same process in binary.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Microprocessor
The microprocessor does the work
• It runs the programs
• It processes the data
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Microprocessor
The microprocessor is connected to the RAM
RAM is just a data store. It holds:
microprocessor
• The data being processed
• The program instructions
These are “fetched” into the processor
as required
RAM
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Basic Plan of any Computer
primary storage (RAM)
ALU
CU
Arithmetic
Logic Unit
Control Unit
•carries out
program
instructions
•fetches data
performs
•calculations
•comparisons
secondary storage
(disks, memory sticks etc)
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Primary Memory
Otherwise known as RAM (random access memory)
or main storage or immediate access store
• RAM stores:
-
program(s) currently being processed
data currently being processed
data on its way to output
data on its way from input
• RAM loses its contents when the power is turned off.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Secondary Memory
• This is persistent memory.
• Used for keeping data between sessions.
• There are many examples:
magnetic
hard disks
tapes
optical
cd
dvd
blu ray
V1.0
solid state
sub notebook PCs
flash memory
camera cards
SIM cards
USB memory sticks
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Registers
• The processor contains special memory cells called
registers
• 5 important examples are:
program counter
holds the address of the next
instruction to be fetched
current instruction register
holds a copy of the instruction
currently being processed
accumulator
holds the data currently being worked on
memory address register
holds the address that is currently active
memory data register
V1.0
holds the data brought from or being sent to RAM
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Machine Cycle
• Most modern computers are based on the same
model, the von Neumann architecture.
• Processing and data are separated.
• What happens:
• The program instructions are loaded into RAM
• The instructions are copied, one by one to the processor
• The instructions are decoded and carried out by the
processor.
• This happens over and over until the program is terminated.
• It is called the machine cycle or the fetch-decode-execute
cycle.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Machine Cycle
The program counter is set to the start address of the program
Remember:
MAR=memory address register
MDR=memory data register
CIR=current instruction register
repeat
the address of the instruction is placed in the MAR
the program counter is incremented by 1
the data in the memory location pointed to by the MAR is copied into the
MDR
the instruction in the MDR is copied into the CIR
the instruction in the CIR is decoded
the instruction is executed
until program terminates
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Machine Cycle
Sometimes this cycle is interrupted
• The program may require a jump
• Another program might be given control of
the processor
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Little Man Computer
• This is a simulation of a working computer.
• It has all the basic features of a real computer
but in a cut-down form.
http://www.atkinson.yorku.ca/~sychen/research/LMC/LMCHome.h
tml
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
The Little Man Computer (LMC)
100 RAM
locations
registers
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: The Instruction Set
• A list of all the possible instructions
• There are 11 possible instructions. A real PC has about 100.
• Each instruction has a code number (machine code) and a
mnemonic (assembly language).
V1.0
LOAD
SUBTRACT
BRANCH IF ZERO
DATA LOCATION
Code:5
mnemonic: LDA
Code: 2
mnemonic: SUB
Code: 7
mnemonic: BRZ
Code : not applicable
mnemonic: DAT
STORE
INPUT
BRANCH IF ZERO OR
POSITIVE
END
Code: 3
mnemonic: STA
Code: 901
mnemonic: INP
ADD
OUTPUT
BRANCH ALWAYS
Code: 1
mnemonic: ADD
Code: 902
mnemonic: OUT
Code: 6
mnemonic: BRA
Code: 8
mnemonic: BRP
Code: 000
mnemonic: HLT
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: What the opcodes mean - 1
LOAD
• Load the content of the address specified into the
accumulator
STORE
• Store the contents of the accumulator in the address specified
ADD
• Add the contents of the specified address to the accumulator
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: What the opcodes mean - 2
SUBTRACT
• Subtract the content of the address specified from the
accumulator.
INPUT
• Copy the value from the In box to the accumulator.
OUTPUT
• Copy the value from the accumulator to the Out box.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: What the opcodes mean - 3
BRANCH IF ZERO
• If the contents of the accumulator are 0, the program counter
will be set to the given address.
BRANCH IF ZERO OR POSITIVE
• If the contents of the accumulator are 0 or positive, the
program counter will be set to the given address.
BRANCH ALWAYS
• Set the contents of the program counter to the given address.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: What the opcodes mean - 4
END
• Stop the program.
DATA LOCATION
• This reserves the next available address for data storage.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: Example program
Instruction meaning
opcode
operand
what happens
901
INPUT
901
none
data goes from the In-box into the
accumulator
320
STORE
3
20
copy data in the accumulator into memory
address 20
901
INPUT
901
none
another data item is taken from the In-box
and it overwrites what is in the
accumulator
120
ADD
1
20
the value in address 20 is added to the
number in the accumulator
902
OUTPUT
902
none
the value in the accumulator is copied to
the Out-box
0
END
0
none
program ends
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
LMC: Example Program
• It adds 2 numbers together.
• With real assembly language, it takes even
more instructions.
• Assembly language takes a lot of effort to
do not very much.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Input and Output
• The Little Man computer receives input from the In-box and
sends output to the Out-box.
• Real computers have input and output devices.
• Input and output devices are slower than the processor.
• The data streams to and from the devices have to be stored
so that the processor is working to full capacity and not kept
waiting.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Input and Output
• The data is queued up in a special part of
memory (RAM) called a buffer.
• The buffer is emptied when the hardware is
ready for the data.
• This is part of device management –
another job for the operating system.
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Input and Output
input
buffer
input
device
output
buffer
output
device
processor
V1.0
© NCC Education Limited
Computer Architecture Unit 2 - 2.‹#›
Unit 2
Any questions?
V1.0
© NCC Education Limited