mod odule 10 a a wor orking com omputer
play

Mod odule 10: A A Wor orking Com omputer 1 CP CPSC SC 121: - PowerPoint PPT Presentation

Mod odule 10: A A Wor orking Com omputer 1 CP CPSC SC 121: 121: the BI BIG ques questions ns How can we build a computer that is able to execute a user-defined program? We are finally able to answer this question. Our


  1. Mod odule 10: A A Wor orking Com omputer 1

  2. CP CPSC SC 121: 121: the BI BIG ques questions ns • 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

  3. Le Learn rning goals: : in-cl 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. 3

  4. Mo Module 10 10 Outline • A little bit of history • Implementing a working computer • Appendix 4

  5. Th The programmable loom 5

  6. Th The Difference Engine 6

  7. Z1 Z1, Z2 Z2, Z3 Z3, … 7

  8. Th The ENIAC 8

  9. 9

  10. Manchester Small-Scale Experimental Machine 10

  11. A A qui quick k roadm dmap p thr hrough ugh our ur cour urse ses • 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. 11

  12. Mo Module 10 10 Outline • A little bit of history • Implementing a working computer • Appendix 12

  13. Vo Von-Ne Neumann a arch chitect cture Memory (contains both programs and data). Arithmetic & Logic Input/Output Control Unit Unit CPU (Central Processing Unit) 13

  14. Memo Me mory • 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). 01010111 ... 0 1 2 3 4 5 6 7 8 9 10 11 ... 14

  15. Me Memo mory • 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

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

  17. Th 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

  18. Ou Our worki king g co 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

  19. Ex Exampl ple ins nstruc uctions ns irmovl 0x1A, %ecx irmovl V, rB R[rB] ← V • What does this instruction do based on its documentation above? a. It adds the constant 0x1A to the value in %ecx. b. It stores the constant 0x1A in %ecx. c. It takes the value at the memory address 0x1A and stores it in %ecx. 19

  20. Ex Exampl ple ins nstruc uctions ns 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

  21. Ex Exampl ple ins nstruc uctions ns subl %eax, %ebx subl rA, rB R[rB] ← R[rB] − R[rA] • What does this instruction do based on its documentation above? a. It calculates the value of %eax minus the value of %ebx and stores the result in %eax. b. It calculates the value of %eax minus the value of %ebx and stores the result in %ebx. c. It calculates the value of %ebx minus the value of %eax and stores the result in %eax. d. It calculates the value of %ebx minus the value of %eax and stores the result in %ebx. 21

  22. Ex Exampl ple ins nstruc uctions ns 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

  23. Ex Exampl ple ins nstruc uctions ns rmmovl %ecx, $8(%ebx) rmmovl rA, D(rB) M[D + R[rB]] ← R[rA] • What does this instruction do based on its documentation above? a. It reads the value in %ebx, adds $8 to it, and stores the result into %ecx. b. It reads the value in %ecx, stores it in the register given by the value of %ebx plus $8. c. It reads the value in %ebx, adds $8 to it and stores it in the memory address given by the value in %ecx. d. It reads the value in %ecx, and stores it in the memory location given by the value in %ebx plus $8. 23

  24. Ex Exampl ple ins nstruc uctions ns 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

  25. Ex Exampl ple ins nstruc uctions ns jge $1000 jge Dest PC ← Dest if last result ≥ 0 25

  26. Ex Exampl ple ins nstruc uctions ns 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

  27. In Inter erpr preting ting an an ins instr truc uctio tion • 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

  28. In Inter erpr preting ting an an ins instr truc uctio tion Example 1: subl %eax, %ebx Represented by 6103 (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

  29. In Inter erpr preting ting an an ins instr truc uctio tion Example 2: irmovl 0x35, %ebx Represented by 30F300000035 (hexadecimal) 0x35 %ebx no register here ignored move constant into a register 29

  30. In Inter erpr preting ting an an ins instr truc uctio tion Example 2: rmmovl %ecx, $8(%ebx) Represented by 401300000008 (hexadecimal) $8 %ebx %ecx ignored register to memory move 30

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

  32. Ex Execut uting ng an n ins nstruc uction Example 1: irmovl 0x35, %ebx 1. Fetch: a. current instruction ← 30F100000035 b. next PC value ← current PC value + 6 2. Decode: nothing needs to be done 3. Execute: valE ← valC 4. Memory: nothing needs to be done 5. Write-back: %ebx ← valE 6. PC update: PC ← next PC value 32

  33. Ex Execut uting ng an n ins nstruc uction Example 2: subl %eax, %ebx 1. Fetch: a. current instruction ← 6103 b. next PC value ← current PC value + 2 2. Decode: a. valA ← value of %eax b. valB ← value of %ebx 3. Execute: valE ← valB – valA 4. Memory: nothing needs to be done. 5. Write-back: %ebx ← valE 6. PC update: PC ← next PC value 33

  34. Ex Execut uting ng an n ins nstruc uction Example 3: rmmovl %ecx, $8(%ebx) 1. Fetch: a. current instruction ← 401300000008 b. next PC value ← current PC value + 6 2. Decode: a. valA ← value of %ecx b. valB ← value of %ebx 3. Execute: valE ← valB + 00000008 4. Memory: M[valE] ← valA 5. Write-back: nothing needs to be done 6. PC update: PC ← next PC value 34

  35. Sa Samp mple program irmovl $3,%eax irmovl $23, %ebx irmovl $facade, %ecx subl %eax, %ebx rmmovl %ecx, $8(%ebx) halt 35

Recommend


More recommend