Bitfields and Logic Basics

Slides:



Advertisements
Similar presentations
Logic Gates.
Advertisements

Logic Gates.
Chapter 4 Gates and Circuits.
Section 10.3 Logic Gates.
9/19/06 Hofstra University – Overview of Computer Science, CSC005 1 Chapter 4 Gates and Circuits.
Informationsteknologi Friday, October 19, 2007Computer Architecture I - Class 81 Today’s class Digital Logic.
Professor Jennifer Rexford COS 217
Lecture 3. Boolean Algebra, Logic Gates
Lecture 3. Boolean Algebra, Logic Gates Prof. Sin-Min Lee Department of Computer Science 2x.
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 16 Digital Circuits, binary Numbers.
Chapter 4 Gates and Circuits. 4–2 Chapter Goals Identify the basic gates and describe the behavior of each Describe how gates are implemented using transistors.
Chapter 4 Gates and Circuits.
CS231: Computer Architecture I Laxmikant Kale Fall 2004.
Lecture 3. Error Detection and Correction, Logic Gates Prof. Sin-Min Lee Department of Computer Science 2x.
Digital Logic Chapter 4 Presented by Prof Tim Johnson
Logic Gates How Boolean logic is implemented. Transistors used as switches to implement Boolean logic: ANDOR Logic with Transistors.
Karnaugh Maps By: Shakil Nobes.
CS1Q Computer Systems Lecture 8
Digital Logic. 4 Why is 32-bit or 64-bit significant in terms of speed, efficiency? 4 Difference between OR and XOR 4 What is a mux for? PLA 4 Two kinds.
Digital Logic Structures MOS transistors logic gates functional units of a computer.
EE2420 – Digital Logic Summer II 2013 Hassan Salamy Ingram School of Engineering Texas State University Set 4: Other Gates.
LOGIC GATES.
4. Computer Maths and Logic 4.2 Boolean Logic Logic Circuits.
CS 352 : Computer Organization and Design University of Wisconsin-Eau Claire Dan Ernst Latches & Flip-Flops.
CS1Q Computer Systems Lecture 7
MIPS Logic & Shift. Bitwise Logic Bitwise operations : logical operations applied to each bit Bitwise OR:
1 Ethics of Computing MONT 113G, Spring 2012 Session 1 Digital Circuits, binary Numbers Course webpage:
Chapter 3 Special Section Focus on Karnaugh Maps.
Introduction to Computing Systems and Programming Digital Logic Structures.
Winter 2016CISC101 - Prof. McLeod1 Today How transistors can carry out commands in a CPU. For example, how to add two integers in an integrated circuit.
 A transistor is the basic building block of electronic components.  The average computer may have millions of them within its circuits.  Essentially,
LOGIC GATES. INTRODUCTION TO LOGIC GATES Boolean functions may be practically implemented by using electronic gates. The following points are important.
Week 1: Introduction and Logic gates IT3002 – Computer Architecture
Logic Gates Unit 16.
Logic gates.
Basics of Logic gates - Part 1
Combinational circuits
Dr.Ahmed Bayoumi Dr.Shady Elmashad
Logic Gates Binary Day 3 PEOPLE 2016.
Morgan Kaufmann Publishers
CS/COE 0447 (term 2181) Jarrett Billingsley
Pseudo-ops and Bitwise Operations
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
CS/COE 0447 (term 2181) Jarrett Billingsley
Minimization and Sequential Logic
Binary Addition and Subtraction
CS231: Computer Architecture I
Computer Fundamentals
Reading: Hambley Chapters
Chapter 4 Gates and Circuits.
Topic 3: Data Binary Arithmetic.
CS140 Lecture 02a: The Machinery of Computation: Circuits and Gates
How Boolean logic is implemented
CISC101 Reminders Your group name in onQ is your grader’s name.
Bitwise Operations and Bitfields
Logic operations.
Computers in the real world Objectives
Logic Gates.
FSMs, Multiplication, and Division
Arithmetic and Decisions
CS/COE 0447 Jarrett Billingsley
CS231: Computer Architecture I
Dr. Clincy Professor of CS
Chapter 3 Special Section
Sequential Logic.
CS231: Computer Architecture I
Bitwise operators.
Digital Circuits and Logic
CS334: Logisim program lab6
Instructor: Michael Greenbaum
Presentation transcript:

Bitfields and Logic Basics CS/COE 0447 (term 2181) Jarrett Billingsley

Class announcements hi :) how did you feel about the exam how's the project goin BREAK THINGS UP INTO FUNCTIONS, OH MY LORD let's look at mine to refresh your memory on how it's supposed to look/work 10/3/2017 CS/COE 0447 term 2181

bonk Read the dang project description. When moving the ball, move along one axis at a time, checking for collision along each axis separately. This will make it much easier. Ball is moving up-right. I'd say: Look right. Is there anything in the way? No? Then we can move there. Look up. Is there anything in the way? Yes? Destroy the block, and flip the vertical velocity. 10/3/2017 CS/COE 0447 term 2181

Checking for block collisions No looping necessary. No "checking each side" necessary. What are the row and column coordinates of each of these blocks? What are the x and y coordinates? If you have an x/y coordinate, can you turn that into a row/col? Once you do that, it's easy. get_block_address! AHAAAA! 10/3/2017 CS/COE 0447 term 2181

Lab 2 feedback Do not write a program all at once and then test it. Never turn in a program that doesn't compile. If your program is crashing, use the blue "step backwards" button after the crash to see what happened. What's the only places you should push/pop registers? DON'T do it around jal. get_block_address is supposed to… get the address of a block. This way you can either lb or sb to that address. 10/3/2017 CS/COE 0447 term 2181

Bitfields 10/3/2017 CS/COE 0447 term 2181

That's this color, in RGB565. The masters of meaning 23 32 19 15 11 10 We can give bit patterns any meaning we want. What if we wanted to store multiple integers in a 16-bit value? 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 red green blue decimal? 23 32 19 That's this color, in RGB565. 10/3/2017 CS/COE 0447 term 2181

I wanna turn the light on!! I have a sequence of 0s. I wanna turn one of them into a 1. What bitwise operation can I use to do that? ? 1 1 10/3/2017 CS/COE 0447 term 2181

I wanna turn the light off!! I wanna turn one of the 1s into a 0. What bitwise operation can I use to do that? 1 1 1 ? 1 1 1 1 1 10/3/2017 CS/COE 0447 term 2181

Turning off the first three, leaving the others alone Again, what operation can we do this with? 1 1 1 1 ? 1 1 1 1 1 10/3/2017 CS/COE 0447 term 2181

Bit shifting Besides AND, OR, and NOT, we can move bits around, too. 1 1 0 0 1 1 1 1 If we shift these bits left by 1… 1 1 0 0 1 1 1 1 0 We stick a 0 at the bottom. 1 1 0 0 1 1 1 1 0 0 Again! 1 1 0 0 1 1 1 1 0 0 0 AGAIN! 1 1 0 0 1 1 1 1 0 0 0 0 AGAIN!!!! 10/3/2017 CS/COE 0447 term 2181

Left-shifting in C/Java and MIPS (animated) C and Java use the << operator for left shift. B = A << 4; // B = A shifted left 4 bits MIPS has the sll (Shift Left Logical) instruction. sll t2, t0, 4 # t2 = t0 << 4 If the bottom 4 bits of the result are now 0s… …what happened to the top 4 bits? 0011 0000 0000 1111 1100 1101 1100 1111 0000 Bit Bucket 10/3/2017 CS/COE 0447 term 2181

<_< >_> <_< <_< >_> <_< We can shift right, too. 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 C/Java use >>, MIPS uses srl (Shift Right Logical). 10/3/2017 CS/COE 0447 term 2181

Let's look at this again. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 red green blue 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 10/3/2017 CS/COE 0447 term 2181

… Hmm. 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 1 10/3/2017 CS/COE 0447 term 2181

Left-shifting and ORing If you have the values of the fields, and you want to put them together into a bitfield, Shift each value left to the correct bit position OR the shifted values together For RGB565, Red is shifted left 11, green is shifted left 5, blue isn't shifted. color = (red << 11) | (green << 5) | blue; 10/3/2017 CS/COE 0447 term 2181

Going the other way Let's go from the bitfield to three separate values. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 We wanna put the red at bit position 0. 1 What about green? 1 Uh oh. 10/3/2017 CS/COE 0447 term 2181

Masquerade In order to isolate only the bits we want, we need a mask. This is a specially-constructed value that has: 1s in the bits that we want to keep 0s in the bits that we want to discard Which bits do we want to keep? Which do we want to discard? 1 & 1 The specially-constructed value is called a mask. 1 10/3/2017 CS/COE 0447 term 2181

Coming up with the mask value If you want to mask a 3 bit value, the mask is 1112. If you want to mask a 5 bit value, it's…? What's 23 in binary? 25? What do you notice about these numbers? 10/3/2017 CS/COE 0447 term 2181

Right-shifting and ANDing If you have a bitfield and you want to extract one or more values, Shift the bitfield right to put the desired value at bit position 0 AND that with 2n-1, where n is the number of bits in the value. For RGB565, The red and blue masks are 25-1 = 31 (or 0x1F) The green mask is 26-1 = 63 (or 0x3F) red = (color >> 11) & 0x1F; green = (color >> 5) & 0x3F; blue = color & 0x1F; 10/3/2017 CS/COE 0447 term 2181

Logic Basics 10/3/2017 CS/COE 0447 term 2181

Transistors Input Input Control Control Output Output A transistor is like a little valve, or switch. The input, output, and control are all single bits. The bits are represented as voltages (maybe 3.3V = 1, 0V = 0). N-type: sends input to output if control is a 1 Input Output Control P-type: sends input to output if control is a 0 Input Output Control Now just put 3 billion of them together! Who said EE was hard? 10/3/2017 CS/COE 0447 term 2181

This little bubble means "invert." Gates We can combine transistors in interesting ways to make gates. A gate implements one of the boolean logic functions. Let's start with the simplest: the NOT gate! Q is the output. A is the input. A Q This little bubble means "invert." 10/3/2017 CS/COE 0447 term 2181

AND, OR, and… XOR? A B Q 1 A B Q 1 A Q B A Q B A Q B We know about AND and OR. But what's XOR? A Q B AND gate A Q B OR gate A Q B XOR gate A B Q 1 A B Q 1 eXclusive OR means "one or the other, but NOT BOTH." 10/3/2017 CS/COE 0447 term 2181

If you give an electrical engineer a NAND gate… If you stick a NOT gate after an AND gate, you get a NAND gate. This kind of gate has a cool property: it's universal. In other words, you can build an entire computer with NANDs. But this isn't how real circuits are designed, at least anymore. Digital logic courses use them cause NAND gate chips are cheap. But in Logisim, we have infinite gates for free :D Use the kind of gate you need for the situation at hand. 10/3/2017 CS/COE 0447 term 2181

Time to bundle up If we want to, say, NOT a 32-bit value, we can draw it like: 32 It's a lot nicer than drawing 32 wires with 32 NOT gates. Logisim calls these wire bundles. It doesn't draw the slashes and numbers though… 10/3/2017 CS/COE 0447 term 2181