information computation communication
play

Information, Computation, Communication Computer Architecture 1 - PowerPoint PPT Presentation

ICC Module System Lesson Computer Architecture Information, Computation, Communication Computer Architecture 1 ICC Module System Lesson Computer Architecture Question Now that we have created algorithms, how can we construct


  1. ICC Module System – Lesson Computer Architecture Information, Computation, Communication Computer Architecture 1

  2. ICC Module System – Lesson Computer Architecture Question ► Now that we have created algorithms, how can we construct systems that execute them ? sum of first n integers Input: n Output: m ??? s ← 0 while n > 0 s ← s + n n ← n – 1 m ← s 2

  3. ICC Module System – Lesson Computer Architecture From Algorithms to Computers sum of first sum of first sum of first n integers n integers n integers Input: n Input: r1 Input: r1 Output: m Output: r2 Output: r2 s ← 0 1: copy r3, 0 1: 0100010100000000 2: jump_egz r1, 6 2: 0101100000001010 while n > 0 3: add r3, r3, r1 3: 0001001001011010 s ← s + n 4: add r1, r1, -1 4: 0001010101000000 n ← n – 1 5: jump 2 5: 0000101010101111 m ← s 6: copy r2, r3 6: 0101000001100101 Software Hardware 3

  4. ICC Module System – Lesson Computer Architecture From Algorithms to Computers Step 1 Step 0 Step 3 sum of first sum of first sum of first n integers n integers n integers Input: n Input: r1 … write them in Input: r1 We will start … and present Output: m Output: r2 Output: r2 terms of a few with the them in a way a s ← 0 1: copy r3, 0 1: 0100010100000000 basic instructions.. algorithms computer can 2: jump_egz r1, 6 2: 0101100000001010 while n > 0 that you have understand. 3: add r3, r3, r1 3: 0001001001011010 s ← s + n 4: add r1, r1, -1 4: 0001010101000000 studied.. n ← n – 1 5: jump 2 5: 0000101010101111 m ← s 6: copy r2, r3 6: 0101000001100101 Software Hardware Step 4 Step 2 …that we will implement In parallel, we will create an with transistors. abstract machine.. 4

  5. ICC Module System – Lesson Computer Architecture From Algorithms to Computers (Step 0) ► In order to describe the idea of an algorithm, we use pseudo code. ► Let’s consider an example sum Input: n Output: m s ← 0 while n > 0 s ← s + n n ← n – 1 m ← s 5

  6. ICC Module System – Lesson Computer Architecture From Algorithms to Computers (Step 1) sum of first sum of first n integers n integers Input: n Input: r1 Output: m Output: r2 s ← 0 1: copy r3, 0 2: jump_egz r1, 6 while n > 0 3: add r3, r3, r1 s ← s + n 4: add r1, r1, -1 n ← n – 1 5: jump 2 m ← s 6: copy r2, r3 Software Hardware We will rewrite algorithm in terms of a few basic instructions, which will have physical counter parts (hardware to perform them). 6

  7. ICC Module System – Lesson Computer Architecture Rewrite Algorithm using Basic Instructions sum of first ► In all computers, values Our machine are store in so-called n integers needs to be able to registers , which are remember values, Input: n physical implementations e.g., value for s Output: m of variables with a fix s ← 0 number of bits (usually while n > 0 32 or 64 bits) s ← s + n n ← n – 1 m ← s 7

  8. ICC Module System – Lesson Computer Architecture Registers ► A register is the physical implementation of the notion of variable ► A machine usually has a small number of register (a few dozens) ► For large data (array, list,..) we will use external memory (RAM), see next lectures ► Registers are usually represented by r1 , r2 , r3 ,… ► We replace all arbitrary variable names by register names § n è r1 § m è r2 § s è r3 8

  9. ICC Module System – Lesson Computer Architecture Step 1.1 sum sum Input: n è r1 Input: r1 Output: m è r2 Output: r2 s ← 0 è r3 r3 ← 0 while n > 0 while r1 > 0 s ← s + n r3 ← r3 + r1 n ← n – 1 r1 ← r1 – 1 m ← s r2 ← r3 9

  10. ICC Module System – Lesson Computer Architecture Next… We will need to sum assign values to registers Input: r1 Output: r2 We will use a r3 ← 0 basic instruction, while r1 > 0 e.g., r3 ← r3 + r1 “copy r3, 0” r1 ← r1 – 1 for r3 ← 0 or r2 ← r3 “copy r2, r3” for r2 ← r3 10

  11. ICC Module System – Lesson Computer Architecture Step 1.2 sum sum Input: r1 Input: r1 Output: r2 Output: r2 r3 ← 0 copy r3, 0 while r1 > 0 while r1 > 0 r3 ← r3 + r1 r3 ← r3 + r1 r1 ← r1 – 1 r1 ← r1 – 1 r2 ← r3 copy r2, r3 11

  12. ICC Module System – Lesson Computer Architecture Next… We will need to assign new values sum to registers Input: r1 after applying Output: r2 arithmetic operations copy r3, 0 We will use while r1 > 0 basic instructions, r3 ← r3 + r1 e.g., r1 ← r1 – 1 “add r3, r3, r1” for r3 ← r3 + r1 copy r2, r3 12

  13. ICC Module System – Lesson Computer Architecture Step 1.3 sum of first sum of first n integers n integers Input: r1 Input: r1 Output: r2 Output: r2 copy r3, 0 copy r3, 0 while r1 > 0 while r1 > 0 r3 ← r3 + r1 add r3, r3, r1 r1 ← r1 – 1 add r1, r1, -1 copy r2, r3 copy r2, r3 13

  14. ICC Module System – Lesson Computer Architecture Basic Instructions ► There is a limited number of instructions, e.g., § copy for assignment § add for addition § mul for multiplication ► All instructions (i) have a single result, (ii) take one or two registers (or constants) as operands ► Instructions are written in the following form: name destination, operand1, operand2 ► Every computation in an algorithm is rewritten in these basic instructions, e.g., a ← a * ( b + c) with a in r1, b in r2 and c in r3 could be rewritten as. add r2, r2, r3 mul r1, r1, r2 14

  15. ICC Module System – Lesson Computer Architecture Next… ► All control structures (if-conditions, while-loop, for-loops, ..) will be sum replaced by jumps to labels Input: r1 ► We will use line numbers as labels Output: r2 ► We will have a few different copy r3, 0 (conditional) jump instructions, while r1 > 0 e.g., add r3, r3, r1 § jump 2: always jump to line 2 add r1, r1, -1 § jump_egz r1, 6: copy r2, r3 jump to line 6, if r1 is equal to zero § jump_eg r1, r2, 6: jump to line 6, if r1 is equal to r2 15

  16. ICC Module System – Lesson Computer Architecture Step 1.4 sum sum Input: r1 Input: r1 Output: r2 Output: r2 copy r3, 0 1: copy r3, 0 while r1 > 0 2: jump_egz r1, 6 add r3, r3, r1 3: add r3, r3, r1 add r1, r1, -1 4: add r1, r1, -1 5: jump 2 copy r2, r3 6: copy r2, r3 This is a program in assembly (or assembler) language . 16

  17. ICC Module System – Lesson Computer Architecture Example in x86 Assembly Language (Intel) r1: n r3: s General form: name src, dst • movl… move long (32bit) • movq...move quad (64 bit) • cmpl…compare long • conditional jump: cmpl+jle 17 Try it yourself : g++ -S sum.cc -o sum.a

  18. ICC Module System – Lesson Computer Architecture Example in x86 Assembly Language (Intel) ► Example in C #include <stdio.h> int main () { int a = 10; int b = 45; int add, mul; __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (a) , "b" (b) ); __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (a) , "b" (b) ); printf("Add = %d \n", add); printf("Mul = %d \n", mul); } Compile with: gcc assembly.c -o assembly -g 18

  19. ICC Module System – Lesson Computer Architecture Summary ► We use “registers” to mimic variables in hardware ► We rewrite our program in terms of basic “instructions” § instructions to load/copy values into a registers § instructions for arithmetic operations § instructions to jump to another instruction under some condition ► We use a restricted set of previously defined instructions ► E.g., ARM or Intel processors have their own set of instructions 19

  20. ICC Module System – Lesson Computer Architecture From Algorithms to Computers (Step 2) sum of first sum of first n integers n integers Input: n Input: r1 Output: m Output: r2 s ← 0 1: copy r3, 0 2: jump_egz r1, 6 while n > 0 3: add r3, r3, r1 s ← s + n 4: add r1, r1, -1 n ← n – 1 5: jump 2 m ← s 6: copy r2, r3 Software Hardware 20

  21. ICC Module System – Lesson Computer Architecture What do we need to calculate? ► Arithmetic logic unit (ALU) for arithmetic (and bitwise) operations 32 + 32 24 = ALU 56 56 24 sum 21

  22. ICC Module System – Lesson Computer Architecture What do we need to calculate? ► Registers to save the values of the operands and the result r1: 2376 r1 read r2: ? 2376 r5 r3: 12 write Registers 54 r4: ? r3 r5: 54 read 12 22

  23. ICC Module System – Lesson Computer Architecture A Circuit to Calculate 2376 A 2388 2388 ALU Registers 12 B Op read write A B sum r3, r3, r1 r3 r3 r1 sum 23

  24. ICC Module System – Lesson Computer Architecture What else do we need? ► Our algorithm or program needs to be stored somewhere sum r3, r3, r1 1: move r3, 0 2: jump_neqz r1, 0, 6 Instruction 3: 3: sum r3, r3, r1 Line 4: sum r1, r1, -1 Memory for 5: jump 2 instructions 6: move r2, r3 ► We need a way to control where we are Next instruction 4: 3: write read Instruction Pointer 4: 24

  25. ICC Module System – Lesson Computer Architecture How to control where we are? A simple circuit that separates the elements in an instruction r3 r3 r1 sum Decoder sum r3, r3, r1 Instruction 3 Instruction Pointer Line Memory for instructions 25

Recommend


More recommend