Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 10: A Working Computer

Similar presentations


Presentation on theme: "Module 10: A Working Computer"— Presentation transcript:

1 Module 10: A Working Computer
7/16/2018 Module 10: A Working Computer 1 1

2 CPSC 121: the BIG questions
7/16/2018 CPSC 121: the BIG questions How can we build a computer that is able to execute a user-defined program? We are finally able to answer this question. Our answer builds up on many of the topics you learned about in the labs since the beginning of the term. 2 2

3 Learning goals: in-class
7/16/2018 Learning goals: in-class Specify the overall architecture of a (Von Neumann) stored program computer – an architecture where both program and data are bits (i.e., state) loaded and stored in a common memory. Trace execution of an instruction through a working computer in a logic simulator (currently logisim): the basic fetch-decode-execute instruction cycle and the data flow to/from the arithmetic logic unit (ALU), the main memory and the Program Counter (PC). Feel confident that, given sufficient time, you could understand how the circuit executes machine- language instructions. - Understand the basics of the von Neumann computer architecture - Understand how instruction is executed in a simple working computer, through the fetch-decode-execute cycle. - Understand how data can flow between different components such as ALU, memory and program counter. 3 3

4 Module 10 Outline A little bit of history
7/16/2018 Module 10 Outline A little bit of history Implementing a working computer Appendix 4 4

5 The programmable loom Joseph Marie Charles a.k.a. Jacquard
7/16/2018 The programmable loom Joseph Marie Charles a.k.a. Jacquard - French weaver and merchant - Invented programmable loom - Loom: A machine used to weave threads together to make cloth and tapestry. - Programmable loom: can specify the design of the cloth using punch cards. - Inspired the invention of other programmable machines 5 5

6 The Difference Engine Charles Babbage:
7/16/2018 The Difference Engine Charles Babbage: - English mathematician, philosopher, inventor and mechanical engineer - Designed the first mechanical computer, called difference engine, but failed to build it. Difference engine: used to calculate values of polynomial functions. Could not finish building it due to funding problems and personality clashes. (8000 parts, 3.3 meters long, 4500 kilograms) (8000 parts, 11 feet long, 5 tons) - Build in London in 2002, about 150 years after it was designed. 6 6

7 7/16/2018 Z1, Z2, Z3, … Konrad Zuse German civil engineer, inventor, and computer pioneer Educated as a civil engineer, graduated in 1935. worked for the Ford Motor Company, using his considerable artistic skills in the design of advertisements He started work as a design engineer at the Henschel aircraft factory in Schönefeld near Berlin. This required the performance of many routine calculations by hand, which he found mind-numbingly boring, leading him to dream of doing them by machine. : Konrad Zuse builds Z1, world's first program-controlled computer. Despite certain mechanical engineering problems it had all the basic ingredients of modern machines, -- using the binary system -- today's standard separation of storage and control. - Program instructions and data are stored on punched film. -- patent application suggested the von Neumann architecture program and data modifiable in storage. 1941: Zuse completes Z3, world's first fully functional programmable computer. 7 7

8 7/16/2018 The ENIAC 1946: the ENIAC was the first programmable electronic computer. It used decimal arithmetic. ENIAC - Electronic Numerical Integrator and Computer - One of the first electronic general-purpose computers. - Designed and primarily used to calculate artillery firing tables for the United States Army's Ballistic Research Laboratory,[5][6] its first programs included a study of the feasibility of the thermonuclear weapon.[7] - ENIAC could be programmed to perform complex sequences of operations, including loops, branches, and subroutines - instead of the stored program computers that exist today, ENIAC was just a large collection of arithmetic machines,[22] which had programs hard coded into the machines with function tables that each contained 1200 ten way switches. - The task of taking a problem and mapping it onto the machine was complex, and usually took weeks - First, the program was figured out on paper, then the cables and switches need to be physically changed. Followed by debugging and verification. - Programming the machine required professionals. Kay McNulty, Betty Jennings, Betty Snyder, Marlyn Meltzer, Fran Bilas, and Ruth Lichterman not only determined how to input ENIAC programs, but also developed an understanding of ENIAC's inner workings.[26][27] The programmers debugged problems by crawling inside the massive structure to find bad joints and bad tubes.[28] Their work was not widely recognized for over 50 years. At the time, the hardware was seen as the primary innovation and the complexity of programming the machine was undervalued 8 8

9

10 Manchester Small-Scale Experimental Machine
7/16/2018 Manchester Small-Scale Experimental Machine The Manchester Small-Scale Experimental Machine (SSEM) - Currently in the Museum of Science and Industry in Manchester. the world's first stored-program computer. It was built at the Victoria University of Manchester, England, by Frederic C. Williams, Tom Kilburn and Geoff Tootill, and ran its first program on 21 June 1948. - Stored program computer: program instructions are stored in electronic memory. The first of three programs written for the machine found the highest proper divisor of 218 (262,144), a calculation that was known would take a long time to run The program consisted of 17 instructions and ran for 52 minutes before getting the correct answer (131,072). performed 3.5 million operations (for an effective CPU speed of 1.1 kIPS). 10 10

11 A quick roadmap through our courses
7/16/2018 A quick roadmap through our courses CPSC 121: learn about gates, and how we can use them to design a circuit that executes very simple instructions. CPSC 213: learn how the constructs available in languages such as Racket, C, C++ or Java are implemented using these simple instructions. CPSC 313: learn how we can design computers that execute programs efficiently and meet the needs of modern operating systems. CPSC 121: Use gates to design circuits to execute simple instructions. CPSC 213: How constructs in programming languages such as Racket, C, Java, are implemented using these simple instructions. CPSC 313: 11 11

12 Module 10 Outline A little bit of history
7/16/2018 Module 10 Outline A little bit of history Implementing a working computer Appendix 12 12

13 Von-Neumann architecture
7/16/2018 Von-Neumann architecture Memory (contains both programs and data). Control Unit Arithmetic & Logic Unit CPU (Central Processing Unit) Input/Output 13 13

14 Memory Contains both instructions and data.
7/16/2018 Memory Contains both instructions and data. Divided into a number of memory locations Think of positions in a list: (list-ref mylist pos) Or in an array: myarray[pos] or arrayList: arrayl.get(pos). ... 1 2 3 4 5 6 7 8 9 10 11 14 14

15 Memory Each memory location contains a fixed number of bits.
7/16/2018 Memory Each memory location contains a fixed number of bits. Most commonly this number is 8. Values that use more than 8 bits are stored in multiple consecutive memory locations. Characters use 8 bits (ASCII) or 16/32 (Unicode). Integers use 32 or 64 bits. Floating point numbers use 32, 64 or 80 bits. 15 15

16 The arithmetic and logic unit
7/16/2018 The arithmetic and logic unit Arithmetic and Logic Unit Performs arithmetic and logical operations (+, -, *, /, and, or, etc). 16 16

17 The control unit Control Unit Decides which instructions to execute.
7/16/2018 The control unit Control Unit Decides which instructions to execute. Executes these instructions sequentially. Not quite true, but this is how it appears to the user. 17 17

18 7/16/2018 Our working computer Implements the design presented in the textbook by Bryant and O'Hallaron (used for CPSC 213/313). A small subset of the IA32 (Intel 32-bit) architecture. It has 12 types of instructions. One program counter register (PC) contains the address of the next instruction. 8 general-purpose 32-bit registers each of them contains one 32 bit value. used for values that we are currently working with. 18 18

19 Example instructions irmovl 0x1A, %ecx irmovl V, rB R[rB] ← V
7/16/2018 Example instructions irmovl 0x1A, %ecx irmovl V, rB R[rB] ← V What does this instruction do based on its documentation above? It adds the constant 0x1A to the value in %ecx. It stores the constant 0x1A in %ecx. It takes the value at the memory address 0x1A and stores it in %ecx. Answer is (b). 19 19

20 Example instructions irmovl 0x1A, %ecx irmovl V, rB R[rB] ← V
7/16/2018 Example instructions irmovl 0x1A, %ecx irmovl V, rB R[rB] ← V This instruction stores a constant in a register. In this case, the value 1A (hexadecimal) is stored in %ecx. 20 20

21 subl rA, rB R[rB] ← R[rB] − R[rA]
7/16/2018 Example instructions subl %eax, %ebx subl rA, rB R[rB] ← R[rB] − R[rA] What does this instruction do based on its documentation above? It calculates the value of %eax minus the value of %ebx and stores the result in %eax. It calculates the value of %eax minus the value of %ebx and stores the result in %ebx. It calculates the value of %ebx minus the value of %eax and stores the result in %eax. It calculates the value of %ebx minus the value of %eax and stores the result in %ebx. Answer is (d). 21 21

22 subl rA, rB R[rB] ← R[rB] − R[rA]
7/16/2018 Example instructions subl %eax, %ebx subl rA, rB R[rB] ← R[rB] − R[rA] The subl instruction subtracts its arguments. The names %eax and %ebx refer to two registers. This instruction takes the value contained in %eax, subtracts it from the value contained in %ebx, and stores the result back in %ebx. 22 22

23 Example instructions rmmovl %ecx, $8(%ebx)
7/16/2018 Example instructions rmmovl %ecx, $8(%ebx) rmmovl rA, D(rB) M[D + R[rB]] ← R[rA] What does this instruction do based on its documentation above? It reads the value in %ebx, adds $8 to it, and stores the result into %ecx. It reads the value in %ecx, stores it in the register given by the value of %ebx plus $8. It reads the value in %ebx, adds $8 to it and stores it in the memory address given by the value in %ecx. It reads the value in %ecx, and stores it in the memory location given by the value in %ebx plus $8. 23 23

24 Example instructions rmmovl %ecx, $8(%ebx)
7/16/2018 Example instructions rmmovl %ecx, $8(%ebx) rmmovl rA, D(rB) M[D + R[rB]] ← R[rA] The rmmovl instruction stores a value into memory (Register to Memory Move). In this case it takes the value in register %ecx. And stores it in the memory location whose address is: The constant 8 PLUS the current value of register %ebx. 24 24

25 Example instructions jge $1000 jge Dest PC ← Dest if last result ≥ 0
7/16/2018 Example instructions jge $1000 jge Dest PC ← Dest if last result ≥ 0 25 25

26 Example instructions jge $1000 This is a conditional jump instruction.
7/16/2018 Example instructions jge $1000 This is a conditional jump instruction. It checks to see if the result of the last arithmetic or logic operation was zero or positive (Greater than or Equal to 0). If so, the next instruction is the instruction stored in memory address 1000 (hexadecimal). If not, the next instruction is the instruction that follows the jge instruction. Documentation: jge Dest PC ← Dest if last result ≥ 0 26 26

27 Interpreting an instruction
7/16/2018 Interpreting an instruction How does the computer know which instruction does what? Each instruction is a sequence of 8 to 48 bits. Some of the bits tell it which instruction it is. Other bits tell it what operands to use. These bits are used as select inputs for several multiplexers. 27 27

28 Interpreting an instruction
7/16/2018 Interpreting an instruction Example 1: subl %eax, %ebx Represented by (hexadecimal) %ebx %eax subtraction arithmetic or logic operation (the use of “6” to represent them instead of 0 or F or any other value is completely arbitrary). 28 28

29 Interpreting an instruction
7/16/2018 Interpreting an instruction Example 2: irmovl 0x35, %ebx Represented by 30F (hexadecimal) 0x35 %ebx no register here ignored move constant into a register 29 29

30 Interpreting an instruction
Example 2: rmmovl %ecx, $8(%ebx) Represented by (hexadecimal) $8 %ebx %ecx ignored register to memory move

31 Six stages of executing an instruction
7/16/2018 Six stages of executing an instruction Fetch: read instruction from memory and decide on new PC value Decode: read values from registers Execute: use the ALU to perform computations Some of them are obvious from the instruction (e.g. subl) Other instructions use the ALU as well (e.g. rmmovl) Memory: read data from or write data to memory Write-back: store value(s) into register(s). PC update: store the new PC value. Not all stages do something for every instruction. 31 31

32 Executing an instruction
7/16/2018 Executing an instruction Example 1: irmovl 0x35, %ebx Fetch: current instruction ← 30F next PC value ← current PC value + 6 Decode: nothing needs to be done Execute: valE ← valC Memory: nothing needs to be done Write-back: %ebx ← valE PC update: PC ← next PC value Fetch: read current instruction from memory. Calculate the next PC value. Decode: nothing. Execute: we temporarily stored the value in valC, move this into valE. Memory: nothing Write back: write the result valE into register %ecx PC update: increment the program counter. 32 32

33 Executing an instruction
7/16/2018 Executing an instruction Example 2: subl %eax, %ebx Fetch: current instruction ← 6103 next PC value ← current PC value + 2 Decode: valA ← value of %eax valB ← value of %ebx Execute: valE ← valB – valA Memory: nothing needs to be done. Write-back: %ebx ← valE PC update: PC ← next PC value 33 33

34 Executing an instruction
Example 3: rmmovl %ecx, $8(%ebx) Fetch: current instruction ← next PC value ← current PC value + 6 Decode: valA ← value of %ecx valB ← value of %ebx Execute: valE ← valB Memory: M[valE] ← valA Write-back: nothing needs to be done PC update: PC ← next PC value

35 7/16/2018 Sample program irmovl $3,%eax irmovl $23, %ebx irmovl $facade, %ecx subl %eax, %ebx rmmovl %ecx, $8(%ebx) halt 35 35

36 The Fetch stage Fetch: read instruction and decide on new PC value
During the Fetch stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

37 The Decode stage Decode: read values from registers
During the Decode stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

38 The Execute stage Execute: use the ALU to perform computation. Some of them are obvious from the instruction (e.g. subl). Other instructions use the ALU as well (e.g. rmmovl) During the Execute stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

39 The Memory stage Memory: read data from or write data to memory
During the Memory stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

40 The Write-back stage Write-back: store value(s) into register(s).
During the Write-back stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

41 The PC Update stage PC update: store the new PC value.
During the PC Update stage, which component of the computer do we work with? Memory Arithmetic and logic unit The 8 general-purpose registers The program counter register None of the above

42 Six stages of executing an instruction
7/16/2018 Six stages of executing an instruction Fetch: read instruction from memory and decide on new PC value Decode: read values from registers Execute: use the ALU to perform computations Some of them are obvious from the instruction (e.g. subl) Other instructions use the ALU as well (e.g. rmmovl) Memory: read data from or write data to memory Write-back: store value(s) into register(s). PC update: store the new PC value. Not all stages do something for every instruction. 42 42

43 Module 10 Outline A little bit of history
7/16/2018 Module 10 Outline A little bit of history Implementing a working computer in Logisim Appendix 43 43

44 Registers and the memory
7/16/2018 Registers and the memory Registers (32 bits each): Instructions that only need one register use F for the second register. %esp is used as stack pointer. Memory contains 232 bytes; all memory accesses load/store 32 bit words. 1 2 3 %eax %esp %ecx %ebp %edx %esi %ebx %edi 4 5 6 7 44 44

45 Register/memory transfers:
7/16/2018 Register/memory transfers: rmmovl rA, D(rB) M[D + R[rB]] ← R[rA] Example: rmmovl %edx, 20(%esi) mrmovl D(rB), rA R[rA] ← M[D + R[rB]] 45 45

46 Data transfer and arithmetic instructions
7/16/2018 Data transfer and arithmetic instructions Other data transfer instructions rrmovl rA, rB R[rB] ← R[rA] irmovl V, rB R[rB] ← V Arithmetic instructions addl rA, rB R[rB] ← R[rB] + R[rA] subl rA, rB R[rB] ← R[rB] − R[rA] andl rA, rB R[rB] ← R[rB] ∧ R[rA] xorl rA, rB R[rB] ← R[rB]  R[rA] 46 46

47 Jumps Unconditional jumps Conditional jumps jmp Dest PC ← Dest
7/16/2018 Jumps Unconditional jumps jmp Dest PC ← Dest Conditional jumps jle Dest PC ← Dest if last result ≤ 0 jl Dest PC ← Dest if last result < 0 je Dest PC ← Dest if last result = 0 jne Dest PC ← Dest if last result ≠ 0 jge Dest PC ← Dest if last result ≥ 0 jg Dest PC ← Dest if last result > 0 47 47

48 Conditional moves cmovle rA, rB R[rB] ← R[rA] if last result ≤ 0
7/16/2018 Conditional moves cmovle rA, rB R[rB] ← R[rA] if last result ≤ 0 cmovl rA, rB R[rB] ← R[rA] if last result < 0 cmove rA, rB R[rB] ← R[rA] if last result = 0 cmovne rA, rB R[rB] ← R[rA] if last result ≠ 0 cmovge rA, rB R[rB] ← R[rA] if last result ≥ 0 cmovg rA, rB R[rB] ← R[rA] if last result > 0 48 48

49 Procedure calls and return support
7/16/2018 Procedure calls and return support call Dest R[%esp]←R[%esp]-4; M[R[%esp]]←PC; PC←Dest;ret PC←M[R[%esp]]; [%esp]←R[%esp]+4 pushl rA R[%esp]←R[%esp]-4; M[R[%esp]]←R[rA] popl rA R[rA]←M[R[%esp]]; R[%esp]←R[%esp]+4 Others: halt, nop 49 49

50 Instruction formats 1 2 3 4 5 halt nop cmovXX rA, rB irmovl V, rB
7/16/2018 Instruction formats 1 2 3 4 5 halt nop cmovXX rA, rB irmovl V, rB rmmovl rA, D(rB) mrmovl D(rB), rA OPI rA, rB jXX Dest call Dest ret pushl rA popl rA 1 2 fn r rB 3 F rB V 4 rA rB D 5 rA rB D 6 fn rA rB 7 fn Dest 8 Dest 9 A rA F B rA F 50 50

51 Instruction formats Arithmetic instructions:
7/16/2018 Instruction formats Arithmetic instructions: addl → fn = 0 subl → fn = 1 andl → fn = 2 xorl → fn = 3 Conditional jumps and moves: jump → fn = 0 jle → fn = 1 jl → fn = 2 je → fn = 3 jne → fn = 4 jge → fn = 5 je → fn = 6 51 51


Download ppt "Module 10: A Working Computer"

Similar presentations


Ads by Google