Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier.

Similar presentations


Presentation on theme: "Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier."— Presentation transcript:

1 Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier

2 For next time Read Chapter 2, posted online with ARM variant. Homework 1 is due tomorrow by 5pm. Homework 2 is out today, due next Friday, the 29 th, at 5pm. MP0 will go live tonight. It will be due Monday February 1 st by 11:59pm.

3 LADIES AND TIGERS

4 The Lady and the Tiger Two doors containing either Ladies or Tigers

5 The Lady and the Tiger Once again, you’ll have to tell Ladies from Tigers A new twist is being added. – In Room I, if a lady is in the room, the sign will be true. If a tiger is in the room, the sign will be false. – In Room II, the situation is the opposite!

6 The Lady and the Tiger Q1 Room I Both rooms contain ladies. Room II Both rooms contain ladies.

7 The Lady and the Tiger Q1 Room IRoom II

8 The Lady and the Tiger Q2 Room I At least one room contains a lady Room II The other room contains a lady

9 The Lady and the Tiger Q2 Room IRoom II

10 The Lady and the Tiger Q3 Room I It makes no difference which room you pick. Room II The other room contains a lady.

11 The Lady and the Tiger Q3 Room IRoom II

12 Moore’s Law Realized

13 It is important to stay current! The future is hard to predict, and the world is changing quickly!

14 Three generations My mother – No running water until she was 8 – Phone was a party line, 6 families shared it – Answering machine when she was 38 Me – Computer in the house when I was born – First access to the internet when I was 13 – First cell phone when I was 21 (analog) You?

15 The future is hard to predict “Heavier-than-air [flying] machines are impossible” – Lord Kelvin, President of the British Royal Society, 1895 “I think there is a world market for maybe five computers” – Thomas Watson, IBM Chairman, 1943 “640K ought to be enough for anybody” – Bill Gates, Microsoft Chairman, 1981

16 The advance of technology and progress 1895 “Heavier-than-air machines are impossible” – Lord Kelvin

17 The advance of technology and progress 1903 (8 years later)

18 The advance of technology and progress

19 1930 (35 years later)

20 The advance of technology and progress

21 1942 (47 years later)

22 The advance of technology and progress

23 1947 (52 years later)

24 The advance of technology and progress

25 1961 (66 years later)

26 The advance of technology and progress

27 1969 (74 years later)

28 The advance of technology and progress

29 Within the span of a single human life, we went from one of the world’s most respected scientists doubting heavier-than-air flight was possible… to landing on the moon.

30 And the pace is accelerating… Moore’s Law The complexity for minimum component costs has increased at a rate of roughly a factor of two per year... Certainly over the short term this rate can be expected to continue, if not to increase. Over the longer term, the rate of increase is a bit more uncertain, although there is no reason to believe it will not remain nearly constant for at least 10 years. That means by 1975, the number of components per integrated circuit for minimum cost will be 65,000. I believe that such a large circuit can be built on a single wafer. - Gorden E. Moore

31 Boolean Algebra

32 Developed by George Boole in 19th Century – Algebraic representation of logic Encode “True” as 1 and “False” as 0 Using true/false values in complicated ways

33 Application of Boolean Algebra Applied to Digital Systems by Claude Shannon – 1937 MIT Master’s Thesis – Reason about networks of relay switches Encode closed switch as 1, open switch as 0 A ~A ~B B Connection when A&~B | ~A&B A&~B ~A&B = A^B

34 Boolean Algebra Gets back to ladies and tigers… Represent truth as 1, and false as 0 – We can operate on values using the following basic operators: AND OR NOT

35 AND X AND Y

36 OR X OR Y

37 NOT NOT X

38 Abbreviations ^ - And v – Or ! – Not !X ^ Y

39 Commutative laws X ^ Y = Y ^ X X v Y = Y v X

40 Associative laws X ^ (Y ^ Z) = (X ^ Y) ^ Z X v (Y v Z) = (X v Y) v Z

41 Distributive laws X ^ (Y v Z) = (X ^ Y) v (X ^ Z) X v (Y ^ Z) = (X v Y) ^ (X v Z)

42 Realization as electronic components AND ORNOT

43 Realization as electronic components AND ORNOT

44 Derived operators X XOR Y – (x v y) ^ !(x ^ y) – Exclusive Or X  Y – (!X v Y) – Implication X = Y – (!X XOR Y)

45 De Morgan’s Laws The negation of a conjunction, is the disjunction of the negations – !(X ^ Y) (!X) v (!Y) – !(X v Y) (!X) ^ (!Y)

46 Boolean Algebra Basic Operations AND OR NOT XOR

47 General Boolean Algebras Operate on Bit Vectors – Operations applied bitwise All of the Properties of Boolean Algebra Apply 01101001 & 01010101 01000001 01101001 | 01010101 01111101 01101001 ^ 01010101 00111100 ~ 01010101 10101010 01000001011111010011110010101010

48 How could we use binary to represent a set?

49 Representing & Manipulating Sets Representation – Width w bit vector represents subsets of {0, …, w–1} – aj = 1 if j ∈ A 01101001{ 0, 3, 5, 6 } 76543210 01010101{ 0, 2, 4, 6 } 76543210 Operations – & Intersection01000001{ 0, 6 } – | Union01111101{ 0, 2, 3, 4, 5, 6 } – ^ Symmetric difference00111100{ 2, 3, 4, 5 } – ~ Complement10101010{ 1, 3, 5, 7 }

50 Bit-Level Operations in C Operations &, |, ~, ^ Available in C – Apply to any “integral” data type long, int, short, char, unsigned – View arguments as bit vectors – Arguments applied bit-wise Examples (Char data type) –~0x41 ➙ 0xBE ~01000001 2 ➙ 10111110 2 –~0x00 ➙ 0xFF ~00000000 2 ➙ 11111111 2 –0x69 & 0x55 ➙ 0x41 01101001 2 & 01010101 2 ➙ 01000001 2 –0x69 | 0x55 ➙ 0x7D 01101001 2 | 01010101 2 ➙ 01111101 2

51 Contrast: Logic Operations in C Contrast to Logical Operators –&&, ||, ! View 0 as “False” Anything nonzero as “True” Always return 0 or 1 Early termination Examples (char data type) –!0x41 ➙ 0x00 –!0x00 ➙ 0x01 –!!0x41 ➙ 0x01 –0x69 && 0x55 ➙ 0x01 –0x69 || 0x55 ➙ 0x01 –p && *p (avoids null pointer access)

52 Shift Operations Left Shift: x << y – Shift bit-vector x left y positions – Throw away extra bits on left Fill with 0 ’s on right Right Shift: x >> y – Shift bit-vector x right y positions Throw away extra bits on right – Logical shift Fill with 0 ’s on left – Arithmetic shift Replicate most significant bit on right Undefined Behavior – Shift amount < 0 or ≥ word size 01100010 Argument x 00010000<< 300011000 Log. >> 2 00011000 Arith. >> 2 10100010 Argument x 00010000<< 300101000 Log. >> 2 11101000 Arith. >> 2 00010000 00011000 000100000010100011101000000100000010100011101000

53 ADDITION AND SUBTRACTION

54 How do we add binary numbers? There are 10 types of people in the world…

55 Adding Binary Numbers 10 11 ??

56 10110001 01101010

57 Unsigned Addition Standard Addition Function – Ignores carry output Implements Modular Arithmetic s= UAdd w (u, v)=u + v mod 2 w u v + u + v True Sum: w+1 bits Operands: w bits Discard Carry: w bits UAdd w (u, v)

58 Visualizing (Mathematical) Integer Addition Integer Addition – 4-bit integers u, v – Compute true sum Add 4 (u, v) – Values increase linearly with u and v – Forms planar surface Add 4 (u, v) u v

59 Visualizing Unsigned Addition Wraps Around – If true sum ≥ 2 w – At most once 0 2w2w 2 w+1 UAdd 4 (u, v) u v True Sum Modular Sum Overflow

60 What does Mathematical Closure Mean?

61 Mathematical Properties Modular Addition Forms an Abelian Group – Closed under addition 0  UAdd w (u, v)  2 w –1 – Commutative UAdd w (u, v) = UAdd w (v, u) – Associative UAdd w (t, UAdd w (u, v)) = UAdd w (UAdd w (t, u ), v) – 0 is additive identity UAdd w (u, 0) = u – Every element has additive inverse Let UComp w (u ) = 2 w – u UAdd w (u, UComp w (u )) = 0

62 BASIC INSTRUCTIONS

63 Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets – But with many aspects in common Early computers had very simple instruction sets – Simplified implementation Many modern computers also have simple instruction sets

64 MIPS vs ARMv6 The book uses the MIPS instruction set. We will be using ARMv6 in our labs. Both are RISC (reduced instruction set computer) architectures. – Many similarities.

65 MIPS Used in many embedded systems – Routers, gateways – Playstation 2 and PSP Invented by Prof John Hennessy at Stanford, the first RISC architecture.

66 ARM Introduced in 1985 Focused on low-power friendly operation. Since 2005, over 98% of all mobile phones had at least one ARM processor. Over 37 billion ARM processors in use in 2013. Currently the dominant processor architecture in the world.

67 Instructions C code: – f = (g + h) – (i + j); Compile ARM code: – add r0, r3, r4 # temp t0 = g + h – add r1, r5, r6 # temp t1 = i + j – sub r2, r0, r1 # f = t0 – t1

68 Register Operands Instructions use registers for operands. Registers are extremely fast SRAM locations that are directly accessible by the processor. – Very fast, but very expensive, so very small.

69 Registers Each register holds a word (4 bytes). Registers r0-r12 are general purpose. NameFunctionNameFunction r0General Purposer8General Purpose r1General Purposer9General Purpose r2General Purposer10General Purpose r3General Purposer11General Purpose r4General Purposer12General Purpose r5General Purposer13Stack Pointer r6General Purposer14Link Register r7General Purposer15Program Counter

70 Registers Registers r13 – r15 have special purposes The PC, r15, is very dangerous. NameFunctionNameFunction r0General Purposer8General Purpose r1General Purposer9General Purpose r2General Purposer10General Purpose r3General Purposer11General Purpose r4General Purposer12General Purpose r5General Purposer13Stack Pointer r6General Purposer14Link Register r7General Purposer15Program Counter

71 Registers The register r13 holds the stack pointer – Also called sp – Points to a special part of memory called the stack. – More about this later.

72 Registers The register r14 holds the link register – Also called lr – Holds the value of a return address that allows for fast and efficient implementation of subroutines.

73 Registers The register r15 holds the program counter – Also called pc – Holds an address of an instruction. Keeps track of where your program is in its execution of machine code. – PC holds the address of the instruction to be fetched next.

74 Registers One additional register, the “current program status register” Four most significant bits hold flags which indicate the presence or absence of certain conditions. 3130292827…87654…0 NZCVReservedIFTMODE

75 Registers N – negative flag Z – zero flag C – carry flag V – overflow flag 3130292827…87654…0 NZCVReservedIFTMODE

76 Registers N – set by an instruction if the result is negative N – negative flag Z – zero flag C – carry flag V – overflow flag 3130292827…87654…0 NZCVReservedIFTMODE

77 Registers Z – set by an instruction if the result of the instruction is zero. N – negative flag Z – zero flag C – carry flag V – overflow flag 3130292827…87654…0 NZCVReservedIFTMODE

78 Registers C – set by an instruction if the result of an unsigned operation overflows the 32-bit register. Can be used for 64-bit arithmetic N – negative flag Z – zero flag C – carry flag V – overflow flag 3130292827…87654…0 NZCVReservedIFTMODE

79 Registers V – works the same as the C flag, but for signed operations. N – negative flag Z – zero flag C – carry flag V – overflow flag 3130292827…87654…0 NZCVReservedIFTMODE


Download ppt "Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier."

Similar presentations


Ads by Google