CS 232: Computer Architecture II - Parallel Programming Laboratory
Download
Report
Transcript CS 232: Computer Architecture II - Parallel Programming Laboratory
CS 232:
Computer Architecture II
Prof. Laxmikant (Sanjay) Kale
CS 232 Objectives:
• Learn about how a computer system, and specifically its
processor, works
–
–
–
–
Assembly language programming
Instruction Set Architecture
Basic Processor design: Data-path and control
An overview of advanced topics
• with specific topics covered in depth
• Example: Pipelining, Caches, I/O, Multiprocessors
Some of the Dos and Don’t
• Must use the class web page regularly
– Important announcements, syllabus, lecture notes (slides),
assignments
• Also, must read the class newsgroup regularly
–
–
–
–
Frequently asked questions
Timely response
Make sure you don’t post solutions
No trash tolerated!
Lets begin with numbers
• Say you wanted to build a machine that calculates the
exact square of any given number quickly.
– 100 years ago
– May want to use the same idea for other things
• calculate cubes?
• Other number calculations?
• Need to decide:
– How are you going to represent the numbers?
– What are you going to build the machine out of?
• Need a basic “smart” component
Representing numbers
• Focus on integers
• Examine our decimal number system:
– Much nicer compared to roman numbers
• How do you add two large numbers in roman representation?
• With weighted positions (ones, tens, hundreds) addition is
easy.
– In fact, we can describe a simple procedure (“algorithm”) for doing it.
– But choice of “10” as the base is somewhat arbitrary
• What base is better for our machine?
– Base 10: need 10 symbols
– Base 2: need 2 symbols (0,1)
• We can probably make machines that can represent 0 and 1
– so that they don’t mix with each other
Binary number representation
• You have done this in CS231
– 11011 is 27
– 35 is 100011
– Addition and subtraction rules are the same as decimal numbers
• Let us agree to use this in our machine
– Still have the problem of having to translate between decimal
system (that we understand) and binary system, that our machine
understands
– Assume we will do it manually, for now
Smart component: Switch
• A switch is either on or off
– To really compose switches to build a machine, we need to be
able to control a switch
• (I.e. if switch A is ON, it will also change switch B to the ON
position).
– Let us assume we have electricity
• Basics: Voltage, Current, Flows if switch is on
• Make a controllable switch
– such that if input voltage is “High”, the switch is “ON” (closed)
– Let us assume “High Voltage” represents 1 and “Low” 0.
Gates
• We can now connect switches together:
– Two switches (A and B) connected in series:
• If both are “ON”, the output is HIGH
• So, if the input to both switch A and switch B is High, the
output of the composite circuit is High
• Let us call this the “AND” circuit (or AND gate)
– You can also connect switches such that:
• If either of the switch is ON, the output is HIGH
• Connect the switches in parallel
• So, if input to A is HIGH or input to B is HIGH, output is
High: AND gate
– NOT gate:
• Input High, Output Low, and vice versa
Gates to Adders
• We can now connect gates together to make an adder:
– Half adder (ignores carry):
• Given two inputs, if exactly one of them 1, then output 1
• Also output carry if both are 1
• How can we connect gates together to make this circuit?
– Full adder:
• uses carry
• 3 inputs lines, two output lines:
– Multi-bit adder:
• Feed the carry of least significant bit to the next higher one
So, we have an adder
• But we needed to square a number….
• The “adder” is just a simple calculating device
– We could connect a lot more of those to make a multiplier, or a
squarer.
– But, we can reuse the same hardware.
– Challenge: just use one adder (say 32 bit adder).
• We need one more type of device:
–
–
–
–
–
to store intermediate results
“Memory”: or registers
We tell the adder to repeatedly add M to a running total.
So, we need to store the running total and M somewhere
Also need to to remember how many times to add (Count)
What does it look like now?
• We have:
– 3 32 bit “registers” : M, result, count
– 1 32 bit adder
– How are they connected?
• We need to bring back M and result to the inputs of the adder
• Store the sum back in result
• bring “count” and “1” to the adder
• store sum in count
• We can use gates to select which register is connected to the
input of the adder
– Also, must decide when the count has reached M
– How to tell when to connect which input to the adder??
Instructions and “Stored Program”
• Let us have a “control unit”
– Tells which inputs are connected,
– Where to store the output
• How does the control unit know what to do?
– Store instructions for it in another set of registers?
– What is an instruction?
• Identifies Input registers, and output register
Let us add memory
• When the amount of data is large:
–
–
–
–
Can’t keep on adding registers
Memory: a linear, random-access storage
Cheaper, slower than registers
Now we need to bring the data from memory into registers and
vice versa