Download Lecture 2 - TAMU Computer Science Faculty Pages

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Computer Architecture
CPSC 321
Andreas Klappenecker
Early History
One of the first calculation tools was the abacus, presumably
invented sometime between 1000-500 B.C.
ENIAC
• All-electronic general purpose
computer based on vacuum tubes
• Intended to calculate ballistic
firing tables
• Designed by Presper Eckert and
John Mauchly
• Designed and constructed during
1943-1946
• Programming by rewiring
• 5000 additions per second, 357
multiplications per second, and
38 divisions per second
• Decimal, not binary!
(photo courtesy of the U.S. army)
Key Inventions
• 1948 Brattain, Shockley and Bardeen invent the
transistor (and receive the Nobel price in 1956)
• 1952 The ferrite core memory is invented and
replaces the vacuum tube memories.
• 1957 Jack Kilby and Robert Noyce invent the silicon
wafer.
• 1961 Steven Hofstein develops the Field Effect
Transistor that will be used in the MOS integrated
circuits
Intel 4004
The first microprocessor, the Intel 4004 with 2300
transistors and 3mmx4mm size, was introduced in 1971.
Intel Pentium 4
The Pentium 4 was introduced in
2000. It had 42 million
transistors and a 1,4001,500MHz clock speed.
The die size was 224mm2
Some Observations
• The main conceptual ideas underlying the
computer have not changed dramatically from
Z3 or EDVAC to modern computers.
• The stored program concepts that was
popularized by von Neumann is still is common
to almost all the computers of our time.
• The technology underwent some dramatic
changes that made the devices much more
energy efficient and significantly smaller.
Computer Architecture
Some people define computer
architecture as the combination of
• the instruction set architecture
(what the executable can see of the
hardware, the functional interface)
• and the machine organization
(how the hardware implements the
instruction set architecture)
What is Computer Architecture ?
Applications
Operating
System
Compiler
Firmware
Instr. Set Proc. I/O system
Datapath & Control
Digital Design
Circuit Design
Layout
Many levels of abstraction
Instruction set
architecture
Machine
organization
How does the course fit into the
curriculum?
In computer science, you can take up to 3 graduate
courses and get credit for it! Do that if you are bored!
CPSC 483 Computer
Sys Design
CPSC 4xx Algorithmic
Aspects of Quantum
Computing
CPSC 321
Computer Architecture
ELEN 220 Intro to
Digital Design
ELEN 248 Intro to
DGTL Sym Design
What next?
• How does better technology help to
improve performance?
• How can we quantify the gain?
• The MIPS architecture
• MIPS instructions
• First contact with assembly language
programming
Performance
• Response time: time between start and
finish of the task (aka execution time)
• Throughput: total amount of work done
in a given time
Question
• Suppose that we replace the processor
in a computer by a faster model
• Does this improve the response time?
• How about the throughput?
Question
• Suppose we add an additional processor
to a system that uses separate
processors for separate tasks.
• Does this improve the response time?
• Does this improve the throughput?
Performance
(Absolute) Performance
Relative Performance
Amdahl’s Law
The execution time after making an
improvement to the system is given by
Exec time after improvement = I/A + E
I = execution time affected by improvement
A = amount of improvement
E = execution time unaffected
Amdahl’s Law
Suppose that program runs 100 seconds on a
machine and multiplication instructions take
80% of the total time. How much do I have to
improve the speed of multiplication if I want my
program to run 5 times faster?
20 seconds = 80 seconds/n + 20 seconds
=> it is impossible!
MIPS Assembly Language
CPSC 321 Computer
Architecture
Andreas Klappenecker
MIPS Assembly Instructions
• add $t0, $t1, $t2
• sub $t0, $t1, $t2
# $t0=$t1+$t2
# $t0=$t1-$t2
• lw $t1, a_addr
• sw $s1, a_addr
# $t1=Mem[a_addr]
# Mem[a_addr]=$t1
Assembler directives
• .text
• .data
• .globl
assembly instructions follow
data follows
globally visible label
= symbolic address
Hello World!
.text
# code section
.globl main
main:
li $v0, 4
# system call for print string
la $a0, str
# load address of string to print
syscall
# print the string
li $v0, 10
# system call for exit
syscall
# exit
.data
str:
.asciiz “Hello world!\n” # NUL terminated string, as in C
Addressing modes
lw $s1, addr
# load $s1 from addr
lw $s1, 8($s0)
# $s1 = Mem[$s0+8]
register $s0 contains the base address
access the address ($s0)
possibly add an offset 8($s0)
Load and move instructions
la $a0, addr
# load address addr into $a0
li $a0, 12
# load immediate $a0 = 12
lb $a0, c($s1)
# load byte $a0 = Mem[$s1+c]
lh $a0, c($s1)
# load half word
lw $a0, c($s1)
# load word
move $s0, $s1
# $s0 = $s1
Control Structures
Assembly language has very few control structures:
 Branch instructions
if cond then goto label
 Jump instructions
goto label
We can build while loops, for loops, repeat-until loops,
if-then-else structures from these primitives
Branch instructions
beqz $s0, label
if $s0==0
goto label
bnez $s0, label
if $s0!=0
goto label
bge $s0, $s1, label
if $s0>=$s1 goto label
ble $s0, $s1, label
if $s0<=$s1 goto label
blt
if $s0<$s1
$s0, $s1, label
goto label
beq $s0, $s1, label
if $s0==$s1 goto label
bgez $s0, $s1, label
if $s0>=0
goto label
if-then-else structures
if ($t0==$t1) then /* blockA */ else /* blockB */
beq $t0, $t1, blockA
j blockB
blockA: … instructions of then block …
j exit
blockB: … instructions of else block …
exit:
… subsequent instructions …
repeat-until loop
repeat … until $t0>$t1
loop: … instructions of loop …
ble $t0, $t1, loop
# if $t0<=$t1 goto loop
Other loop structures are similar…
Exercise: Derive templates for various loop structures
System calls
• load argument registers
• load call code
• syscall
li $a0, 10
li $v0, 1
syscall
# load argument $a0=10
# call code to print integer
# print $a0
SPIM system calls
procedure
print int
print float
print double
print string
code $v0
argument
$a0 contains number
1
$f12 contains number
2
$f12 contains number
3
$a0 address of string
4
SPIM system calls
procedure
code $v0
result
read int
5
res returned in $v0
read float
6
res returned in $f0
read double
7
res returned in $f0
read string
8
Example programs
• Loop printing integers 1 to 10
1
2
3
• Increasing array elements by 5
for(i=0; i<len; i++) {
a[i] = a[i] + 5;
}
Print numbers 1 to 10
main:
loop:
li $s0, 1
# $s0 = loop counter
li $s1, 10
# $s1 = upper bound of loop
move $a0, $s0
# print loop counter $s0
li $v0, 1
syscall
li $v0, 4
# print “\n”
la $a0, linebrk
# linebrk: .asciiz “\n”
syscall
addi $s0, $s0, 1
# increase counter by 1
ble $s0, $s1, loop
# if ($s0<=$s1) goto loop
li $v0, 10
# exit
syscall
Increase array elements by 5
.text
.globl main
main:
loop:
la
$t0, Aaddr
# $t0 = pointer to array A
lw
$t1, len
# $t1 = length (of array A)
sll
$t1, $t1, 2
# $t1 = 4*length
add
$t1, $t1, $t0
# $t1 = address(A)+4*length
lw
$t2, 0($t0)
# $t2 = A[i]
addi $t2, $t2, 5
# $t2 = $t2 + 5
sw
# A[i] = $t2
$t2, 0($t0)
addi $t0, $t0, 4
# i = i+1
bne
# if $t0<$t1 goto loop
$t0, $t1, loop
.data
Aaddr:
.word 0,2,1,4,5
len:
.word 5
# array with 5 elements
Increase array elements by 5
.text
.globl main
main: la $t0, Aaddr
# $t0 = pointer to array A
lw $t1, len
# $t1 = length (of array A)
sll $t1, $t1, 2
# $t1 = 4*length (byte addr.)
add $t1, $t1, $t0
# $t1 = beyond last elem. A
Increase array elements by 5
Loop: lw
$t2, ($t0)
# $t2 = A[i]
addi $t2, $t2, 5
# $t2 = $t2 + 5
sw $t2, ($t0)
# A[i] = $t2
addi $t0, $t0, 4
# i = i+1
bne $t0, $t1, loop # if $t0<$t1 goto loop
li $v0, 10
syscall
# exit
Increase array elements by 5
.data
Aaddr:.word 0,2,1,4,5
len:
.word 5
Idiosyncratic: Byte addressing => loop in steps of 4
Describe meaning of registers in your documentation!
Conclusion
• Read Chapter 2 in Patterson, Hennessy,
2nd edition
• Lab 0 requires you to become familiar
with the lab environment
• Do some exercises on your own!
• Read Appendix A in 2nd edition