Introduction to
Computing
Topic 2 : Computer Architecture
Summary of the Lecture
• Data representation
• What’s inside
• The processor
• Memory
• The machine cycle
• Input/output
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
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
Digital Computers
Most information can be coded into digital
signals.
Music
Images Program instructions
File Data Types
• If you look at the files on your storage medium, you will see
a wide range of different types of data:
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
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
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
Bits and Bytes
256 combinations can give you:
• 256 different whole numbers (0-255)
• 256 different characters:
• 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
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!
Bytes are Versatile
Bytes can be integers:
00000001 =1
00000010=2
00000011=3
00000100=4
00000101=5
00000110=6
00000111=7
etc.
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
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.
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:
Address 0-100 101-200 201-300 301-400 401-500
Content instruction numbers letters other spare
s data
It all depends
The software determines what the bytes mean:
Integers
Fractional numbers
Text
Images
Sound
Program instructions
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
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 4 2 1
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
Number Systems
• There is a another way:
• Hexadecimal otherwise known as hex
• Based on the number 16
• 16 digits
• 0123456789ABCDEF
• Each column is worth 16x the one on the right
4096 256 16 1
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
Hexadecimal
• So…..
• hexadecimal is shorthand for binary
• 1 hex digit is worth 4 binary digits
• F = 1111 = 15
hex binary decimal
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
Arithmetic
Add 0110 + 0011
That is 6 + 3 = 9 in decimal
0110
0011
1001
carry→ 1 1
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.
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.
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.
Floating point numbers
In decimal:
1.456 E4
mantissa exponent
This is a shorthand way of saying:
14560
(move the point 4 places to the right)
It’s the same process in binary.
The Microprocessor
• The microprocessor does the work
• It runs the programs
• It processes the data
The Microprocessor
The microprocessor is connected to the RAM
RAM is just a data store. It holds:
The data being processed
microprocessor The program instructions
These are “fetched” into the processor as
required
RAM
The Basic Plan of any Computer
primary storage (RAM)
ALU CU
Arithmetic Control Unit
Logic Unit
•carries out
performs program
•calculations instructions
•comparisons •fetches data
secondary storage
(disks, memory sticks etc)
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.
Secondary Memory
• This is persistent memory.
• Used for keeping data between sessions.
• There are many examples:
magnetic solid state
hard disks sub notebook PCs
tapes flash memory
optical camera cards
cd SIM cards
dvd USB memory sticks
blu ray
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 holds the data brought from or being sent to RAM
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.
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
The Machine Cycle
• Sometimes this cycle is interrupted
• The program may require a jump
• Another program might be given control of the processor
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.
The Little Man Computer (LMC)
100 RAM
locations
registers
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).
LOAD SUBTRACT BRANCH IF ZERO DATA LOCATION
Code:5 Code: 2 Code: 7 Code : not
mnemonic: LDA mnemonic: SUB mnemonic: BRZ applicable
mnemonic: DAT
STORE INPUT BRANCH IF ZERO END
OR POSITIVE
Code: 3 Code: 901 Code: 000
mnemonic: STA mnemonic: INP Code: 8 mnemonic: HLT
mnemonic: BRP
ADD OUTPUT BRANCH ALWAYS
Code: 1 Code: 902 Code: 6
mnemonic: ADD mnemonic: OUT mnemonic: BRA
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
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.
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.
LMC: What the opcodes mean - 4
• END
• Stop the program.
• DATA LOCATION
• This reserves the next available address for data storage.
LMC: Example program
Instructi meaning opcode operand what happens
on
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
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.
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.
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.
Input and Output
input input
buffer device
processor
output output
buffer device