VIEWS: 47 PAGES: 44 POSTED ON: 10/14/2011
Architecture des ordinateurs Juri Luca De Coi Saint-Etienne, France, 12-09-2011 Outline • Introduction: Philosophical issues • How to implement a UTM – How to represent states and tape symbols – How to implement the transition function • Interpretation of bit strings – Meaningful interpretations – Meaningful operations for such interpretations Outline • Introduction: Philosophical issues • How to implement a UTM – How to represent states and tape symbols – How to implement the transition function • Interpretation of bit strings – Meaningful interpretations – Meaningful operations for such interpretations Theory vs practice (I) Theory: investigates formal properties of models Practice: creates real-world instantiations of models They have something in common • Everything should be made as simple as possible, but no simpler (attributed to A. Einstein) They have something different • The definition of “simple” Theory vs practice (II) Theory: essential models are easier to investigate Practice: full-fledged instantiations are easier to use My personal opinion (sorry for that) • Theory is useless without practice • Practice is meaningless without theory Outline • Introduction: Philosophical issues • How to implement a UTM – How to represent states and tape symbols – How to implement the transition function • Interpretation of bit strings – Meaningful interpretations – Meaningful operations for such interpretations The ingredients of a UTM • Two finite sets S (state set) and T (tape set) • A given s0S (initial state) to represent the elements of such sets? Howgiven t T (blank symbol) • A 0 • A function S×TS×T×{right, left, nothing} How to implement • The input consists of such function? – a representation of a Turing Machine TM – TM’s input • It processes TM’s input as described in TM’s representation How to represent the elements of S/T (I) By means of • mechanical signals? – Babbage’s Analytical Engine • thermic signals? • electronic signals? Electronic signals sn Different values of an sn-1 electronic quantity might represent different symbols s2 • e.g., voltage s1 PRO • Are the fastest signals in nature CONTRA • Electricity costs – The higher VS , the more expensive it is n • Physical quantities are continuous The real world Values are not constant Transitions take time Bits Only two values of an electronic quantity are typically used • Above (resp. below) a threshold t1 (resp. t2) NOTE: This is not mandatory • The ternary computer Setun The two values are typically denoted by 0 and 1 NOTE: 0 (resp. 1) does not necessarily denote the lower (resp. higher) value How to represent the elements of S/T (II) • If #S/#T≤2, one bit would make it • What if #S/#T>2? – Just use bit strings • How long should such strings be? – ≥ log2#S/#T Bit string’s length Bit string’s name 4 Nibble 8 Byte 16 Word 32 Doubleword 64 Quadword 128 Octword Representation of bit strings Binary notation • 1010011001012 or 101001100101b Octal notation • For strings whose length is a multiple of 3 • 51458 Hexadecimal notation • For strings whose length is a multiple of 4 • A6516 or A65h NOTE: String elements read left-to-right Typical mappings Binary Hexadecimal Binary Octal 0000 0 0001 1 000 0 0010 2 001 1 0011 0100 3 4 010 2 0101 0110 5 6 011 3 0111 1000 7 8 100 4 1001 1010 9 A or a 101 5 1011 1100 B or b C or c 110 6 1101 D or d 1110 E or e 111 7 1111 F or f Outline • Introduction: Philosophical issues • How to implement a UTM – How to represent states and tape symbols – How to implement the transition function • Interpretation of bit strings – Meaningful interpretations – Meaningful operations for such interpretations The ingredients of a UTM • Two finite sets S (state set) and T (tape set) • A given s0S (initial state) to represent the elements of such sets? Howgiven t T (blank symbol) • A 0 • A function S×TS×T×{right, left, nothing} How to implement • The input consists of such function? – a representation of a Turing Machine TM – TM’s input • It processes TM’s input as described in TM’s representation UTM-based architectures Many UTM-based architectures have been proposed • Von Neumann architecture • (Modified) Harvard architecture (and some non UTM-based ones • Lisp machines ) UTMs vs von Neumann machines (VNMs–I) (U)TMs perform over and over the following steps 1. Read a symbol from the current cell 2. Based on the read symbol and the current state – write a symbol to the same cell – possibly move the tape’s head to the cell on the right/left – move to the new state UTMs vs VNMs (II) Von Neumann-based computers perform over and over the following steps 1. Read one or more symbols starting from the current cell (fetch) 2. (Assume that it describes a TM T to emulate) 3. Behave as described by the read symbol (execute) The last step might require to • read/write one or more symbols to arbitrary cells and/or • move the tape’s head to an arbitrary cell and/or • move to the new state The ingredients of a VNM • Two finite sets S (state set) and T (tape set) • A given s0S (initial state) Typically, where 1≤i≤n (Main) Memory Ri • A given t0T (blank symbol) of bytes (or words) • typically, the set • is the set of bytes/…/octwords • called a register • is A function S×TS×T×{right, left, nothing} Enforced by the central processing unit (CPU) • The input consists of – a representation of a Turing Machine TM – TM’s input Instruction • It processes TM’s input as described in TM’s Data representation Outline • Introduction: Philosophical issues • How to implement a UTM – How to represent states and tape symbols – How to implement the transition function • Interpretation of bit strings – Meaningful interpretations – Meaningful operations for such interpretations Representation vs interpretation Representation Interpretation Representation การแสดง குறிப்பிடுதல் Representation נציגות Different people represent the प्रतितितित्व 代表 same concept differently αντιπροςώπευςη 表現 ներկայացում نمایندگی 대표 التمثيل представление Interpretation Different people interpret the same object differently Interpretations of bits Interpretations of bits • As bits • As booleans – Each of 0 and 1 can be interpreted as either false or true What can we do with bits? • Compare two of them • Set them to 0/1 (clear/set) What can we do with booleans? • Compare two of them • AND/OR… two of them • Negate them Interpretations of bit strings • As bit strings • As boolean strings • As (un)signed integers • As (un)packed binary-coded decimals (BCDs) • As memory addresses • As instructions Bit strings as bit strings Bit strings of length n can encode n two-valued properties of an entity EX: Filesystem permissions under Unix • Each of – file owner – members of the file owner’s group – others can be (not) authorized to – read – write – execute the file Bit strings as boolean strings: Masks Given a bit string bn…b0 and a bit bi belonging to it, how to 1. check if bi is 0 or 1? 2. set/clear/flip bi? W.r.t. point 1. i-th position • Build a bit string 0…1…0 • Interpret both bit strings as boolean strings • AND them n+1 • bi is 0 iff the result is 0…0 What can we do with bit/boolean strings? • Perform bit/boolean operations on (a subset of) the string – Not really string-oriented operations • Compare two of them • Count the number of 0/1 (resp. false/true) in the string • Right/Left-rotate the string of n positions • Right/Left-shift the string of n positions – What do we add to the other end? Bit strings as unsigned integers Bits can have two values A bit string can be interpreted as an unsigned integer’s base-2 representation PROBLEM: Unsigned integers are infinite • What is the biggest unsigned integer which can be represented with n bits? Bit strings as (signed) integers Naïve representation • All bits but bi are interpreted as the integer’s base-2 representation • bi is interpreted as the sign EX PROBLEMS • 0 has two representations (00…0 and 10…0) • Different algorithms are required to add (subtract) integers with equal or different sign Two’s complement representation Given a bit string of length n • a positive integer <2n-1 is represented as the corresponding unsigned integer prefixed by 0 • a negative integer ≥-2n-1 is represented as the unsigned integer 2n+1+i – Just flip all bits and add 1 PROBLEM: Integers are infinite • What are the smallest/biggest integers which can be represented with n bits? Bit strings as (un)packed BCDs (I) How can unsigned integers be represented by means of bit strings? • As we just saw • By encoding the digits of the integer’s base-10 representation – Base-10 uses 10 (different) digits – To represent them, we need bit strings long (at least) log210=4 • … Bit strings as (un)packed BCDs (II) A byte contains 8 bits Each byte can contain up to 2 decimal digits (Un)packed BCDs are byte strings where each byte encodes 2 (resp. 1) decimal digit(s) What can we do with integers? • Compare two of them • (For signed integers) Find the opposite of an integer • Add two of them • Subtract one from another • Multiply two of them • (Integer-)Divide one by another • Compute the rest of the division of one by another Problems • What if the result does not fit in a bit string as long as the operands? (Assuming that results and operands are represented in the same way) – That is the typical case for multiplication – Carry/Borrow and overflow • What if division by 0 is attempted? • The algorithms valid for (unsigned) integers do not work for BCDs Bit strings as addresses UTM • The tape’s head can only move to the cell directly at right/left (if it moves) VNM • The tape’s head can move to an arbitrary cell How to find the right cell? – Each cell is identified by an address Address space The number of memory cells a VNM can address EX: Intel 8088 (resp. 8086, Pentium) had an address space of 28 (resp. 220, 232) NOTE: Not all addresses necessarily identify • a physical memory cell – Not all computers have all memory they could • a memory cell – Memory-mapped I/O (vs port-mapped I/O) • Faster • More flexible • Bigger address space Bit strings as instructions UTM: the tape contains • a representation of the TM T to simulate • T’s input Different representations of the same TM are possible Different UTMs are possible Bit strings as instructions VNM: the memory contains • a representation of the TM T to simulate (instructions) • T’s input (data) Different representations of the same TM are possible Different instruction sets are possible – They do not necessarily contain the same instructions – They might represent the same instruction differently Machine code 03 3b 84 00 01 1a 05 68 3b a7 ff f9 i.e. • From now on 1. Put 0 in some memory cell 2. Increment the cell’s content by 1 3. Double the cell’s content Not really user-friendly, what do you think? Assembly language iconst_0 Push the integer constant 0 istore_0 Pop to memory cell n° 0 iinc 0, 1 Increment the content of memory cell n° 0 by 1 iload_0 Push the content of memory cell n° 0 iconst_2 Push the integer constant 2 imul Pop two integers, multiply them and push the result istore_0 Pop to memory cell n° 0 goto -7 Jump back to the beginning Assembly vs machine code Immediate value cmp ecx, 5 Instruction jnz Continue Mnemonic for registers lea eax, [ebx] Memory reference Continue: Label Operands Mnemonic for opcodes Assemblers translate assembly language statements into machine code by • translating mnemonics into opcodes • resolving symbolic names To recap What does this mean? 0305h