CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce

advertisement
CSE115 / CSE503
Introduction to Computer Science I
Dr. Carl Alphonce
343 Davis Hall
alphonce@buffalo.edu
Office hours:
Thursday 12:00 PM – 2:00 PM
Friday 8:30 AM – 10:30 AM
OR request appointment via e-mail
PROFESSIONALISM
Turn off and put away electronics:
cell phones
pagers
laptops
tablets
etc.
© Dr. Carl Alphonce
Class today
ROADMAP
Instruction decoding
Fetch/Decode/Execute cycle
Low-level and high-level languages
Coming up
Expressions and objects
© Dr. Carl Alphonce
ACM MEETING
Association for Computing Machinery
http://ubacm.org
next meeting
Wednesday, Feb 3
7:00 PM
Davis Hall, 2nd floor atrium
FREE PIZZA!!
© Dr. Carl Alphonce
GATES
© Dr. Carl Alphonce
AND gate
inputs are on left
output is on right
For which input values is output 1?
For which input values is output 0?
0 or 1
Truth table for AND
Input 1
0
0
1
1
Input 2
0
1
0
1
Output
0
0
0
1
OR gate
inputs are on left
output is on right
For which input values is output 1?
For which input values is output 0?
Truth table for OR
Input 1
0
0
1
1
Input 2
0
1
0
1
Output
0
1
1
1
NOT gate
input is on left
output is on right
For which input value is output 1?
For which input value is output 0?
Truth table for NOT
Input
0
1
Output
1
0
channel 1
WhatarethecorrectoutputvaluesforanORgate?
A.
B.
C.
D.
E.
F.
G.
H.
0,0,0,0
0,0,0,1
0,0,1,0
0,0,1,1
0,1,0,0
0,1,0,1
0,1,1,0
0,1,1,1
Input 1
0
0
1
1
Input 2
0
1
0
1
Output
?
?
?
?
WhatarethecorrectoutputvaluesforanORgate?
A.
B.
C.
D.
E.
F.
G.
H.
0,0,0,0
0,0,0,1
0,0,1,0
0,0,1,1
0,1,0,0
0,1,0,1
0,1,1,0
0,1,1,1
Input 1
0
0
1
1
Input 2
0
1
0
1
Output
?
?
?
?
WhatarethecorrectoutputvaluesforanORgate?
A.
B.
C.
D.
E.
F.
G.
H.
0,0,0,0
0,0,0,1
0,0,1,0
0,0,1,1
0,1,0,0
0,1,0,1
0,1,1,0
0,1,1,1
Input 1
0
0
1
1
Input 2
0
1
0
1
Output
?
?
?
?
MEMORY
© Dr. Carl Alphonce
Flip-flop (a bit of memory)
The normal value of both R and S is zero
R (reset) = 0
remembered
value
S (set) = 0
INSTRUCTION
DECODING
© Dr. Carl Alphonce
Computer Organization
Memory
(RAM)
11010010
11010010
11010010
11010010
11010010
Processor (CPU)
R1
R2
...
R16
PC
IR
11010010
11010010
ALU
Encoding instructions
Example:
Digital Equipment Corp PDP 11
photo credit:
https://commons.wikimedia.org/wiki/File:Pdp-11-70-panel.jpg
by Dave Fischer
Encoding instructions (PDP 11)
0110000001000010
Encoding instructions (PDP 11)
0110000001000010
a sequence of 0s and 1s
0110
bit groupings
000001 000010
Encoding instructions (PDP 11)
0110000001000010
a sequence of 0s and 1s
0110
000001 000010
bit groupings
OpCode
Arg1
general pattern
Arg2
Encoding instructions (PDP 11)
0110000001000010
a sequence of 0s and 1s
0110
000001 000010
bit groupings
OpCode
Arg1
Arg2
general pattern
ADD
Reg1
Reg2
specific instruction
Instruction decoding
“ADD”
OP CODE
R1
R2
0110000001000010
Circuitry to decode
rest of instruction and
carry it out (“execute”
the instruction)
This wire will carry a 1
only if the op code of
the instruction is 0110.
Instruction decoding
OP CODE
R1
R2
t t t t t t t t t t t t t t t t
This wire will carry a 1
only if the op code of
the instruction is 1100.
This wire will carry a 1
only if the op code of
the instruction is 1101.
This wire will carry a 1
only if the op code of
the instruction is 1110.
Controlling information flow
Data from a register
Data to ALU
FETCH
DECODE
EXECUTE
cycle
© Dr. Carl Alphonce
Fetch-Decode-Execute cycle
Fetch an instruction (& update PC)
Decode instruction
Fetch
(load instruction
into IR from
location in PC)
Execute instruction
Execute
Update PC
Decode
channel 1
Howwouldyouratethecoursesofar?
A.
B.
C.
D.
Toofastand/orconfusing
AlittlefastbutIamhangingon
Prettygood– llearnedsomethingnew
Review– Iknewthisallfrombefore
Last semester
© Dr. Carl Alphonce
Language levels
1940s
HARDWARE
Language levels
1940s
MACHINE LANGUAGE
(0110000001000010)
HARDWARE
Language levels
1940s
ASSEMBLY LANGUAGE
(ADD R1 R2)
MACHINE LANGUAGE
(0110000001000010)
HARDWARE
Language levels
1940s
ASSEMBLY LANGUAGE
(ADD R1 R2)
MACHINE LANGUAGE
(0100000001000010)
ASSEMBLY
HARDWARE
Language levels
1950s
HIGH LEVEL LANGUAGE (e.g. Java)
x+y
ASSEMBLY LANGUAGE
(ADD R1 R2)
MACHINE LANGUAGE
(0110000001000010)
ASSEMBLY
HARDWARE
Language levels
1950s
COMPILATION
HIGH LEVEL LANGUAGES
x+y
ASSEMBLY LANGUAGE
(ADD R1 R2)
MACHINE LANGUAGE
(0110000001000010)
ASSEMBLY
HARDWARE
Language levels
HIGH LEVEL LANGUAGES
x+y
ASSEMBLY LANGUAGE
(ADD R1 R2)
MACHINE LANGUAGE
(0110000001000010)
HARDWARE
}
LOW
LEVEL
LANGUAGES
Download