DOC PREVIEW
UCLA COMSCI 33 - CS33 Week 2 Discussion Slides

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Midterm TopicsMidterm TopicsOverview for TodayHomework 1Slide 6Lab 1Signed vs. Unsigned in CSign ExtensionSign Extension ExampleSummary: Expanding, Truncating: Basic RulesCasting SurprisesWhy Should I Use Unsigned?Slide 14Fixed Point FractionsFloating PointFloating PointFloating Point - NormalizedSlide 19VideoFloating Point- DenormalizedFloating Point - Special ValsIA32 General Purpose RegistersSome Other RegistersA Simple ExampleWhat really happens...Slide 27Slide 28Slide 29Simple Addressing ModesSlide 31Moving DataLinux DemoMidterm TopicsCS 33 Week 2 DiscussionMidterm Topics1. Integer Binary data - encode/decode (2s complement, binary to/from decimal and hexadecimal) - size conversion (sign extend) - operations (add, multiply) - fractional fixed point2. Floating point - encode/decode normalized - denormalized - operations3. Boolean operations - truth tables (&, |, ^, ~)4. Assembly Language - operands5. Stack operationMidterm Topics1. Integer Binary data - encode/decode (2s complement, binary to/from decimal and hexadecimal) - size conversion (sign extend) - operations (add, multiply) - fractional fixed point2. Floating point - encode/decode normalized - denormalized - operations3. Boolean operations - truth tables (&, |, ^, ~)4. Assembly Language - operands5. Stack operationOverview for Today●Homework 1 Solution●Questions about Lab 1?●Unsigned/Signed Integer●Review Floating Point●Review Assembly Language●Midterm Review (Midterm 1 next Wed, Oct. 22)●C/Linux tutorialHomework 1●Determine if my system is little-endian or big-endian.23HexHex2345 674501Lab 1●Due Sunday at 6:00 PM●Please submit only lab1.c file●Questions?Carnegie Mellon8Signed vs. Unsigned in CConstantsBy default are considered to be signed integersUnsigned if have “U” as suffix0U, 4294967259UCastingExplicit casting between signed & unsigned same as U2T and T2Uint tx, ty;unsigned ux, uy;tx = (int) ux;uy = (unsigned) ty;Implicit casting also occurs via assignments and procedure callstx = ux;uy = ty;Carnegie Mellon9Sign ExtensionTask:Given w-bit signed integer xConvert it to w+k-bit integer with same valueRule:Make k copies of sign bit:X  = xw–1 ,…, xw–1 , xw–1 , xw–2 ,…, x0k copies of MSB• • •X X • • • • • •• • •wwkCarnegie Mellon10Sign Extension ExampleConverting from smaller to larger integer data typeC automatically performs sign extension short int x = 15213; int ix = (int) x; short int y = -15213; int iy = (int) y;Decimal Hex Binaryx152133B 6D 00111011 01101101ix1521300 00 3B 6D 00000000 00000000 00111011 01101101y-15213C4 93 11000100 10010011iy-15213FF FF C4 93 11111111 11111111 11000100 10010011Carnegie Mellon11Summary:Expanding, Truncating: Basic RulesExpanding (e.g., short int to int)Unsigned: zeros addedSigned: sign extensionBoth yield expected resultTruncating (e.g., unsigned to unsigned short)Unsigned/signed: bits are truncatedResult reinterpretedUnsigned: mod operationSigned: similar to modFor small numbers yields expected behavourCarnegie Mellon120 0U == unsigned-1 0 < signed-1 0U > unsigned2147483647 -2147483648 > signed2147483647U -2147483648 < unsigned-1 -2 > signed(unsigned) -1 -2 > unsigned 2147483647 2147483648U < unsigned 2147483647 (int) 2147483648U > signedCasting SurprisesExpression EvaluationIf there is a mix of unsigned and signed in single expression, signed values implicitly cast to unsignedIncluding comparison operations <, >, ==, <=, >=Examples for W = 32: TMIN = -2,147,483,648 , TMAX = 2,147,483,647Constant1Constant2Relation Evaluation0 0U-1 0-1 sizeof(int)2147483647-2147483647-1 2147483647U -2147483647-1 -1 -2 (unsigned)-1-2 2147483647 2147483648U 2147483647 (int) 2147483648UCarnegie Mellon13Why Should I Use Unsigned?Don’t Use Just Because Number NonnegativeEasy to make mistakesunsigned i;for (i = cnt-2; i >= 0; i--) a[i] += a[i+1];Can be very subtle#define DELTA sizeof(int)int i;for (i = CNT; i-DELTA >= 0; i-= DELTA) . . .Do Use When Performing Modular ArithmeticMultiprecision arithmeticDo Use When Using Bits to Represent SetsLogical right shift, no sign extensionCarnegie Mellon14A Programmer’s PerspectiveFixed Point FractionsDecimal:42.2510 = 101*4 + 100*2 + 10-1*2 + 10-2*5 = 10 *4 + 1 *2 + 0.1*2 + 0.01*5Binary:6.2510 = 110.012 = 22*1 + 21*1 + 20*0 + 2-1*0 + 2-2*1 = 4 *1 + 2 *1 + 1 *0 + ½*0 + ¼ *1What are the problems with this type of representation of fractions?Floating Point●The idea is to store a fractional number in a more compact form, similar to using scientific notation in decimal.●In base 10, we can store very large numbers and very small numbers using powers of 10.4.505 * 1015 HUGE3.768 * 10-25 tinySimilarly, we may store Binary numbers in this way:1011000 * 2201010110 * 2-15Say we want to store a really small number, like 0.00000001012We can normalize it by moving the decimal place over so it begins with a 1.This becomes 0.00000001012 = 1.012 * 2-8Just like in Base 10, think of 2-8 as moving the decimal place over 8 spots.In general, the Value V = (-1)S * M * 2Ewhere S = Sign (+), M = Mantissa (1.012), E = Exponent (-8)Floating PointFloating Point - Normalized- exponent is not all 0s and not all 1s. Leading 1 assumed. Mantissa = 1.f●Normalized is the most common case for floating point numbers.●s is a 0 or 1 for a positive or negative number.●f represents the fraction without the leading 1 (which is assumed).○e.g. 0.00010111 is 1.0111 * 2-4○So here our Mantissa is 1.0111 and Exponent is -4○But we assume there is a leading 1 in the Mantissa (because normalized), so we save a bit of memory and only store bits 0111 as f.●e represents the exponent with a “Bias” added on, called a signed integer in biased form.○We add 2k-1-1 to the exponent where k is the number of bits allocated for the exponent, then store that number. For single precision, this is 28-1-1 = 127○For the above example, our exponent is -4, so we would add 127 to that and store 123 in unsigned binary form.Thus our normalized representation of 0.00010111 is0 01111011 01110000000000000000000eFormula for converting decimal to normalized floating point numberExample number = 3/321. Convert Base 10 number to base 2 number3/32 = 1/16 + 1/32 = 2-4 + 2-5 = 0.000112. Is your number positive or


View Full Document

UCLA COMSCI 33 - CS33 Week 2 Discussion Slides

Download CS33 Week 2 Discussion Slides
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS33 Week 2 Discussion Slides and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS33 Week 2 Discussion Slides 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?