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

Slides:



Advertisements
Similar presentations
When NOT to use Unsigned? Don’t Use Just Because Number Nonzero – C compilers on some machines generate less efficient code unsigned i; for (i = 1; i
Advertisements

Cosc 2150: Computer Organization Chapter 3: Boolean Algebra and Digital Logic.
Lecture 1: Introduction II EEN 112: Introduction to Electrical and Computer Engineering Professor Eric Rozier, 1/16/2013.
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
CSCE 212 Computer Organization Lecture 2 Data Representation.
CS213 Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication.
Bits and Bytes CS 213 Aug. 27, 1998 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and.
Bits and Bytes January 17, 2002 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and strings.
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
Memory - Registers Instruction Sets
ICS 2005 Instructor: Peter A. Dinda TA: Bin Lin Recitation 2.
Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
EET 2261 Unit 2 HCS12 Architecture
February 4, 2003 CSCE 212 Computer Architecture Lecture 3 Representing Integers.
Fabián E. Bustamante, Spring 2007 Bits and Bytes Today Why bits? Binary/hexadecimal Byte representations Boolean algebra Expressing in C.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Carnegie Mellon 1 This Week: Integers Integers  Representation: unsigned and signed  Conversion, casting  Expanding, truncating  Addition, negation,
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Fall 2012: FCM 708 Foundation I Lecture 2 Prof. Shamik Sengupta
CS 270: Computer Organization Bits, Bytes, and Integers
Bits and Bytes Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C.
Lecture 3: Computation and Representation CS 2011 Fall 2014, Dr. Rozier.
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
1 CS232: Computer Architecture II Fall 2011 Intel i7 Quad-core.
Bits and Bytes Topics Why bits? Tell me Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
Bits, Bytes, and Integers Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C Representations of Integers Basic.
1 Saint Louis University Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides.
Arithmetic Logic Unit (ALU) Anna Kurek CS 147 Spring 2008.
– 1 – Number Systems Number of symbols = base of the system Most intuitive -- base 10 (decimal system) counting on fingertips symbols
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Logic Design / Processor and Control Units Tony Diep.
Bits and Bytes Boolean Algebra ( ) Boolean algebra Expressing in C.
Bits and Bytes Topics Why bits? Representing information as bits
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
CS232: Computer Architecture II
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
1 Manipulating Information (1). 2 Outline Bit-level operations Suggested reading –2.1.7~
Lecture 4: Representing Negative Numbers CS 2011 Spring 2016, Dr. Rozier.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
Computer Architecture & Operations I
Morgan Kaufmann Publishers
Today’s Instructor: Randy Bryant
This Week: Integers Integers Summary
Bits, Bytes, and Integers CSE 238/2038/2138: Systems Programming
Morgan Kaufmann Publishers
Instructor: David Ferry
Representing Information
Representing Information (2)
Bits and Bytes Topics Representing information as bits
Bits, Bytes, and Integers January 16, 2008
Bits and Bytes Topics Representing information as bits
Bits and Bytes Boolean algebra Expressing in C
Bits and Bytes Topics Representing information as bits
Bits, Bytes, and Integers 2nd Lectures
Bits and Bytes Topics Representing information as bits
“The Class That Gives CMU Its Zip!”
Bits and Bytes Topics Representing information as bits
Arithmetic Topics Basic operations Programming Implications
Representing Information (2)
Introduction to Microprocessor Programming
Comp Org & Assembly Lang
Comp Org & Assembly Lang
Computer Organization COMP 210
Operations and Arithmetic
“The Class That Gives CMU Its Zip!”
“The Class That Gives CMU Its Zip!”
Lecture 2: Bits, Bytes, Ints
Presentation transcript:

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

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.

LADIES AND TIGERS

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

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!

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

The Lady and the Tiger Q1 Room IRoom II

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

The Lady and the Tiger Q2 Room IRoom II

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

The Lady and the Tiger Q3 Room IRoom II

Moore’s Law Realized

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

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?

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

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

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

The advance of technology and progress

1930 (35 years later)

The advance of technology and progress

1942 (47 years later)

The advance of technology and progress

1947 (52 years later)

The advance of technology and progress

1961 (66 years later)

The advance of technology and progress

1969 (74 years later)

The advance of technology and progress

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.

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

Boolean Algebra

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

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

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

AND X AND Y

OR X OR Y

NOT NOT X

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

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

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

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

Realization as electronic components AND ORNOT

Realization as electronic components AND ORNOT

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

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)

Boolean Algebra Basic Operations AND OR NOT XOR

General Boolean Algebras Operate on Bit Vectors – Operations applied bitwise All of the Properties of Boolean Algebra Apply & | ^ ~

How could we use binary to represent a set?

Representing & Manipulating Sets Representation – Width w bit vector represents subsets of {0, …, w–1} – aj = 1 if j ∈ A { 0, 3, 5, 6 } { 0, 2, 4, 6 } Operations – & Intersection { 0, 6 } – | Union { 0, 2, 3, 4, 5, 6 } – ^ Symmetric difference { 2, 3, 4, 5 } – ~ Complement { 1, 3, 5, 7 }

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 ~ ➙ –~0x00 ➙ 0xFF ~ ➙ –0x69 & 0x55 ➙ 0x & ➙ –0x69 | 0x55 ➙ 0x7D | ➙

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)

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 Argument x << Log. >> Arith. >> Argument x << Log. >> Arith. >>

ADDITION AND SUBTRACTION

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

Adding Binary Numbers ??

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)

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

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

What does Mathematical Closure Mean?

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

BASIC INSTRUCTIONS

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

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.

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

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 Currently the dominant processor architecture in the world.

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

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.

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

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

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.

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.

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.

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

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

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

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 …87654…0 NZCVReservedIFTMODE

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 …87654…0 NZCVReservedIFTMODE

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 …87654…0 NZCVReservedIFTMODE