Today: Bits, Bytes, and Integers. Bits, Bytes, and Integers. For example, can count in binary. Everything is bits. Encoding Byte Values

Size: px
Start display at page:

Download "Today: Bits, Bytes, and Integers. Bits, Bytes, and Integers. For example, can count in binary. Everything is bits. Encoding Byte Values"

Transcription

1 Today: Bits, Bytes, and Integers Representing information as bits Bits, Bytes, and Integers CSci : Machine Architectre and Organization September th-9th, Yor instrctor: Stephen McCamant Bit-level maniplations Integers Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Based on slides originally by: Randy Bryant, Dave O Hallaron Representations in memory, pointers, strings Everything is bits For example, can cont in binary Each bit is or By encoding/interpreting sets of bits in varios ways Compters determine what to do (instrctions) and represent and maniplate nmbers, sets, strings, etc Why bits? Electronic Implementation Easy to store with bistable elements Reliably transmitted on noisy and inaccrate wires Base Nmber Representation Represent 53 as Represent. as.[] Represent.53 X as. X 3.V.9V.V.V 3 Encoding Byte Vales Aside: ASCII table Byte bits Binary to Decimal: to 55 Hexadecimal to FF Base nmber representation Use characters to 9 and A to F Write FAD37B in C as xfad37b xfad37b A B C D 3 E F a b c d e f x_ \ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O x_ ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ESC FS GS RS US x_ SPC! " # $ % & ' ( ) * +, -. / x3_ : ; < >? A B C D E F G H I J K L M N O x5_ P Q R S T U V W X Y Z [ \ ] ^ _ x_ ` a b c d e f g h I j k l m n o x7_ p q r s t v w x y z { ~ DEL 5

2 Example Data Representations C Data Type Typical 3-bit Typical -bit Today: Bits, Bytes, and Integers x- char short int long float doble long doble / pointer 7 Boolean Algebra Developed by George Boole in 9th Centry Or (math: ) A&B when both A and B A B when either A or B ~A when A 9 ^ ~ All of the properties of Boolean algebra apply Width w bit vector represents sbsets of {,, w aj if j A 753 Bit-Level Operations in C Representation & A^B when either A or B, bt not both Example: Representing & Maniplating Sets Operate on bit vectors Exclsive-Or xor (math: ) Operations applied bitwise Encode Tre as and False as Not (math: ) Representations in memory, pointers, strings General Boolean Algebras And (math: ) Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Algebraic representation of logic Representing information as bits Bit-level maniplations Integers Operations &,, ~, ^ Available in C Apply to any integral data type long, int, short, char, nsigned View argments as bit vectors Argments applied bit-wise {, 3, 5, Examples (Char data type) ~x xbe 753 {,,, Operations & ^ ~ Intersection Union Symmetric difference Complement ~ ~x xff ~ x9 & x55 x {, {,, 3,, 5, {, 3,, 5 {, 3, 5, 7 & x9 x55 x7d

3 Contrast: Logic Operations in C Shift Operations Contrast to Logical Operators Left Shift: x << y View as False Anything nonzero as Tre Always retrn or Early termination (AKA short-circit evalation ) Throw away extra bits on left Fill with s on right Watch ot for && vs. & (and vs. ) Examples (char data type) of the more common oopsies in!x one x!x C x programming Arith. >> Right Shift: x >> y Argment x Throw away extra bits on right Logical shift: fill with s on left Arithmetic shift: replicate most significant bit on left << 3 Log. >> Arith. >> Undefined Behavior Shift amont < or word size Signed shift into or ot of sign bit (i.e., arith. behavior not assred) (avoids nll pointer access) << 3 Log. >> Shift bit-vector x right y positions!!x x x9 && x55 x x9 x55 x p && *p Argment x Shift bit-vector x left y positions &&,,! 3 Interlde: ChimeIn Today: Bits, Bytes, and Integers Which of the following nmbers represented in hex is not a mltiple of? x73c xfd5f9e xca9 x97bd9 xac3f97 Representing information as bits Bit-level maniplations Integers Idea: it is enogh to look at the last digit Like divisibility by, and 5 for decimal x, x, x, and xc decimal are mltiples of xe is even bt not a mltiple of 5 Binary Nmber Property Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Representations in memory, pointers, strings Smmary Encoding Integers Claim Unsigned BU(X ) w- w w- + å i w w : x y w- + w w + w w+ BT (X ) xw Decimal Hex 3B D C 93 w w xi i i Sign Bit Binary Sign Bit For s complement, most significant bit indicates sign w Two s Complement i C short bytes long Assme tre for w-: xi short int x 53; short int y -53; w i i for nonnegative for negative 3

4 For-bit Example, nsigned For-bit Example, sign + magnitde Unsigned: 5 This approach can represent throgh 5 Sign + magnitde: Negate if -7 This approach can represent -7 throgh 7 Disadvantages: special cases, - 3 For-bit Example, two s complement For-bit Example Two s complement: - - Unsigned: 5 Two s complement: - This approach can represent - throgh 7-5 Encoding Integers Unsigned BU(X) w x i i i short int x 53; short int y -53; C short bytes long Sign Bit For s complement, most significant bit indicates sign for nonnegative for negative Two s Complement BT(X) x w w w x i i i Decimal Hex Binary x 53 3B D y -53 C 93 Sign Bit 7 Two-complement Encoding Example (Cont.) x 53: y -53: Weight Sm 53-53

5 Nmeric Ranges Unsigned Vales UMin UMax w Vales for W Two s Complement Vales TMin w TMax w Other Vales Mins Decimal Hex Binary UMax 5535 FF FF TMax 377 7F FF TMin FF FF Vales for Different Word Sizes W 3 UMax 55 5,535,9,97,95,,7,73,79,55,5 TMax 7 3,77,7,3,7 9,3,37,3,5,775,7 TMin - -3,7 -,7,3, -9,3,37,3,5,775, Observations TMin TMax + Asymmetric range UMax * TMax + C Programming #inclde <limits.h> Declares constants, e.g., ULONG_MAX LONG_MAX LONG_MIN Vales platform specific 9 3 Unsigned & Signed Nmeric Vales X BU(X) BT(X) Eqivalence Same encodings for nonnegative vales Uniqeness Every bit pattern represents niqe integer vale Each representable integer has niqe bit encoding Can Invert Mappings UB(x) BU - (x) Bit pattern for nsigned integer TB(x) BT - (x) Bit pattern for two s comp integer Today: Bits, Bytes, and Integers Representing information as bits Bit-level maniplations Integers Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Representations in memory, pointers, strings 3 3 Mapping Between Signed & Unsigned Two s Complement x Unsigned x TU TB X BU Maintain Same Bit Pattern UT UB X BT Maintain Same Bit Pattern Unsigned x Two s Complement x Mappings between nsigned and two s complement nmbers: Keep bit representations and reinterpret Mapping Signed Unsigned Bits Signed TU UT Unsigned

6 Mapping Signed Unsigned Bits Signed Unsigned 3 Relation between Signed & Unsigned Two s Complement 3 TB X x BU Maintain Same Bit Pattern w x x /- Large negative weight becomes Large positive weight 3 37 Signed vs. Unsigned in C Conversion Visalized Unsigned TU x s Comp. Unsigned UMax UMax Ordering Inversion Negative Big Positive Constants By defalt are considered to be signed integers Unsigned if have U as sffix U, 99759U TMax + TMax TMax s Complement Range Unsigned Range Casting Explicit casting between signed & nsigned same as UT and TU int tx, ty; nsigned x, y; tx (int) x; y (nsigned) ty; Implicit casting also occrs via assignments and procedre calls tx x; y ty; TMin 3 Casting and Comparison Srprises Casting and Comparison Srprises Expression Evalation Expression Evalation If there is a mix of nsigned and signed in single expression, If there is a mix of nsigned and signed in single expression, signed vales implicitly cast to nsigned Inclding comparison operations <, >,, <, > Examples for W 3: TMIN -,7,3,, TMAX,7,3,7 Inclding comparison operations <, >,, <, > Examples for W 3: TMIN -,7,3,, TMAX,7,3,7 Constant Constant Relation Evalation U U U U nsigned < signed > nsigned signed vales implicitly cast to nsigned Constant U 737U - - (nsigned) - (nsigned) Constant U U U U U 73U (int) 73U 73U (int) Relation Evalation nsigned < signed > > nsigned signed < nsigned > > signed nsigned < nsigned > signed

7 Brief annoncements Abot week left to go on HA Keep yor qestions coming, don t pt it off My office hors tomorrow will move to 3-pm Still in -5E Keller Smmary Casting Signed Unsigned: Basic Rles Bit pattern is maintained Bt reinterpreted Can have nexpected effects: adding or sbtracting w Expression containing signed and nsigned int int is cast to nsigned!! 3 Typical Usage Malicios Usage /* Declaration of library fnction memcpy */ void *memcpy(void *dest, void *src, size_t n); typedef nsigned long size_t; /* Kernel memory region holding ser-accessible data */ #define KSIZE char kbf[ksize]; /* Kernel memory region holding ser-accessible data */ #define KSIZE char kbf[ksize]; /* Copy at most maxlen bytes from kernel region to ser bffer */ int copy_from_kernel(void *ser_dest, int maxlen) { /* Byte cont len is minimm of bffer size and maxlen */ int len KSIZE < maxlen? KSIZE : maxlen; memcpy(ser_dest, kbf, len); retrn len; /* Copy at most maxlen bytes from kernel region to ser bffer */ int copy_from_kernel(void *ser_dest, int maxlen) { /* Byte cont len is minimm of bffer size and maxlen */ int len KSIZE < maxlen? KSIZE : maxlen; memcpy(ser_dest, kbf, len); retrn len; #define MSIZE 5 #define MSIZE 5 void getstff() { char mybf[msize]; copy_from_kernel(mybf, MSIZE); printf( %s\n, mybf); void getstff() { char mybf[msize]; copy_from_kernel(mybf, -MSIZE);... 5 Today: Bits, Bytes, and Integers Sign Extension Representing information as bits Bit-level maniplations Integers Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Representations in memory, pointers, strings Task: Given w-bit signed integer x Convert it to w+k-bit integer with same vale Rle: Make k copies of sign bit: X x w,, x w, x w, x w,, x k copies of MSB X w 7 X k w 7

8 Sign Extension Example Smmary: Expanding, Trncating: Basic Rles short int x 53; int ix (int) x; short int y -53; int iy (int) y; Decimal x ix y iy Hex 3B 3B C FF FF C Binary D D Unsigned: zeros added Signed: sign extension Both yield expected reslt Trncating (e.g., nsigned to nsigned short) Converting from smaller to larger integer data type C atomatically performs sign extension 9 UAddw(, v) Tre Sm: w+ bits Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Discard Carry: w bits Standard Addition Fnction Implements Modlar Arithmetic s 5 UAddw(, v) + v mod w 5 Visalizing Unsigned Addition Visalizing (Mathematical) Integer Addition Add(, v) -bit integers, v Compte tre sm Ignores carry otpt Representations in memory, pointers, strings Smmary Add(, v) Vales increase linearly with and v Forms planar srface +v +v Operands: w bits Integer Addition 5 Unsigned Addition Representing information as bits Bit-level maniplations Integers Unsigned/signed: bits are trncated Reslt reinterpreted Unsigned: mod operation Signed: similar to mod For small nmbers yields expected behavior Today: Bits, Bytes, and Integers Expanding (e.g., short int to int) Overflow Wraps Arond If tre sm w At most once Integer Addition UAdd(, v) 3 Tre Sm w+ Overflow v w 53 Modlar Sm v 5

9 Two s Complement Addition Mathematical Properties Modlar Addition Forms an Abelian Grop Tre Sm: w+ bits UAddw(, v) w Commtative UAddw(, v) UAddw(v, ) Associative UAddw(t, UAddw(, v)) UAddw(UAddw(t, ), v) is additive identity UAddw(, ) Every element has additive inverse Let UCompw ( ) w UAddw(, UCompw ( )) Discard Carry: w bits TAdd and UAdd have Identical Bit-Level Behavior Will give s t 55 5 NegOver Tre Sm w w PosOver bits s comp. integer TAddw(, v) Visalizing s Complement Addition Fnctionality Drop off MSB Treat remaining bits as int s, t,, v; s (int) ((nsigned) + (nsigned) v); t + v TAdd Overflow Tre sm reqires w+ Signed vs. nsigned addition in C: + v +v Operands: w bits Closed nder addition -bit two s comp. Range from - to +7 TAdd Reslt Vales Wraps Arond If sm w Becomes negative At most once If sm < w Becomes positive At most once w w NegOver TAdd(, v) v PosOver 5 Positive Overflow Characterizing TAdd Mathematical Properties of TAdd Isomorphic Grop to nsigneds with UAdd TAddw(, v) UT(UAddw(TU( ), TU(v))) TAdd(, v) > v < Fnctionality Tre sm reqires w+ bits Drop off MSB Treat remaining bits as s Since both have identical bit patterns < Negative Overflow comp. integer Two s Complement Under TAdd Forms a Grop Sign Bit Set Closed, Commtative, Associative, is additive identity Every element has additive inverse TComp w () TMinw TMinw TMinw w v w TAddw (,v) v v ww 59 v TMin w > TAdd(, v) > v < < > (NegOver) TMinw v TMax w TMax w v (PosOver) 9

10 Signed/Unsigned Overflow Differences Sign bit table, signed ordering Unsigned: Overflow if carry ot of last position Also jst called carry (C) Signed: Reslt wrong if inpt signs are the same bt otpt sign is different In CPUs, nqalified overflow sally means signed (O or V) UAdd(, v) v < v > TAdd(, v) Positive Overflow > < Carry Ot < v > Negative Overflow TAdd(, v) > < Sign Bit Set Sign bit table, nsigned ordering Negation: Complement & Increment Claim: Following Holds for s Complement ~x + -x Complement Observation: ~x + x - x ~x Complement & Increment Examples Mltiplication x 53 Decimal Hex Binary x 53 3B D ~x -5 C 9 ~x+ -53 C 93 y -53 C 93 x Decimal Hex Binary ~ - FF FF ~+ Goal: Compting Prodct of w-bit nmbers x, y Either signed or nsigned Bt, exact reslts can be bigger than w bits Unsigned: p to w bits Reslt range: x * y ( w ) w w+ + Two s complement min (negative): Up to w- bits Reslt range: x * y ( w )*( w ) w + w Two s complement max (positive): Up to w bits, bt only for (TMin w ) Reslt range: x * y ( w ) w So, maintaining exact reslts wold need to keep expanding word size with each prodct compted is done in software, if needed e.g., by arbitrary precision arithmetic packages 5

11 Unsigned Mltiplication in C Signed Mltiplication in C Operands: w bits Tre Prodct: *w bits v Discard w bits: w bits * v UMlt w (, v) Operands: w bits Tre Prodct: *w bits v Discard w bits: w bits * v TMlt w (, v) Standard Mltiplication Fnction Ignores high order w bits Implements Modlar Arithmetic UMlt w (, v) v mod w Standard Mltiplication Fnction Ignores high order w bits Some of which are different for signed vs. nsigned mltiplication Lower bits are the same 7 Code Secrity Example # XDR Code SUN XDR library Widely sed library for transferring data between machines void* copy_elements(void *ele_src[], int ele_cnt, size_t ele_size); ele_src malloc(ele_cnt * ele_size) void* copy_elements(void *ele_src[], int ele_cnt, size_t ele_size) { /* * Allocate bffer for ele_cnt objects, each of ele_size bytes * and copy from locations designated by ele_src */ void *reslt malloc(ele_cnt * ele_size); if (reslt NULL) /* malloc failed */ retrn NULL; void *next reslt; int i; for (i ; i < ele_cnt; i++) { /* Copy object i to destination */ memcpy(next, ele_src[i], ele_size); /* Move pointer to next memory region */ next + ele_size; retrn reslt; 9 7 XDR Vlnerability Power-of- Mltiply with Shift malloc(ele_cnt * ele_size) What if: ele_cnt + ele_size 9 Allocation?? Chime in: (Qestion 57) ( + ) How can I make this fnction secre? Operation << k gives * k Both signed and nsigned Operands: w bits Tre Prodct: w+k bits k Discard k bits: w bits UMlt w (, k ) TMlt w (, k ) Examples << 3 * ( << 5) ( << 3) * Most machines shift and add faster than mltiply * k k 7 7

12 Compiled Mltiplication Code Backgrond: Ronding in Math C Fnction long ml(long x) { retrn x*; Compiled Arithmetic Operations leaq (%rax,%rax,), %rax salq $, %rax Explanation t <- x+x* retrn t << ; C compiler atomatically generates shift/add code when mltiplying by constant How to rond to the nearest integer? Cannot have both: rond(x + k) rond(x) + k (k integer), translation invariance rond(-x) -rond(x) negation invariance x, read floor : always rond down (to - ):.,.7, x, read ceiling : always rond p (to + ):.,.7, -. - C integer operators mostly se rond to zero, which is like floor for positive and ceiling for negative 73 7 Division in C Undefined behavior Integer division /: ronds towards Choice (settled in C99) is historical, via FORTRAN and most CPUs Division by zero: ndefined, sally fatal Unsigned division: no overflow possible Signed division: overflow almost impossible Exception: TMin/- is n-representable, and so ndefined On x this too is a defalt-fatal exception Many things yo shold not do are officially called ndefined by the C langage standard Meaning: compiler can do anything it wants Examples: Accessing beyond the ends of an array Dividing by zero Overflow in signed operations Shifts of negative vales Things yo do in this section of the corse! Bad interaction with improving compiler optimizers Gap between standard and lenient practical compilers not yet resolved 75 7 Unsigned Power-of- Divide with Shift Compiled Unsigned Division Code Qotient of Unsigned by Power of >> k gives / k Uses logical shift k Operands: / k Division: / k. Reslt: / k Binary Point C Fnction nsigned long div (nsigned long x) { retrn x/; Compiled Arithmetic Operations shrq $3, %rax Explanation # Logical shift retrn x >> 3; Division Compted Hex Binary x B D x >> D B x >> B x >> B Uses logical shift for nsigned For Java Users Logical shift written as >>> 77 7

13 Signed Power-of- Divide with Shift Correct Power-of- Divide Qotient of Signed by Power of x >> k gives x / k Uses arithmetic shift Ronds wrong direction when < / k x / k Want x / k (Rond Toward ) Compte as (x+k-)/ k k Binary Point RondDown(x / k) Division: Reslt: x Operands: Qotient of Negative Nmber by Power of Case : No ronding Dividend:. In C: (x + (<<k)-) >> k Biases dividend toward k +k y y >> y >> y >> Division Compted Hex C 93 E 9 FC 9 FF C Binary Divisor: Binary Point. Biasing has no effect 79 / k / k Compiled Signed Division Code Correct Power-of- Divide (Cont.) C Fnction Case : Ronding Dividend: x +k k long idiv(long x) { retrn x/; Incremented by Divisor: / k x / k testq %rax, %rax js L L3: sarq $3, %rax ret L: addq $7, %rax jmp L3 Binary Point. Incremented by Remainder operator Uses arithmetic shift for int For Java Users Today: Bits, Bytes, and Integers Written as % in C x % y is the remainder after division x / y E.g., x % is the lowest digit of non-negative x Behavior for negative vales matches / s ronding toward zero Representing information as bits Bit-level maniplations Integers I.e. sign of remainder matches sign of dividend (Some other langages have other conventions: sign of reslt eqals sign of divisor, sometimes distingished as modlo, or always positive) b*(a / b) + (a % b) a if x < x + 7; # Arithmetic shift retrn x >> 3; Arith. shift written as >> Biasing adds to final reslt Explanation Compiled Arithmetic Operations 3 Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Representations in memory, pointers, strings 3

14 Arithmetic: Basic Rles Arithmetic: Basic Rles Addition: Unsigned/signed: Normal addition followed by trncate, same operation on bit level Unsigned: addition mod w Mathematical addition + possible sbtraction of w Signed: modified addition mod w (reslt in proper range) Mathematical addition + possible addition or sbtraction of w Unsigned ints, s complement ints are isomorphic rings: isomorphism casting Left shift Unsigned/signed: mltiplication by k Always logical shift Mltiplication: Unsigned/signed: Normal mltiplication followed by trncate, same operation on bit level Unsigned: mltiplication mod w Signed: modified mltiplication mod w (reslt in proper range) Right shift Unsigned: logical shift, div (division + rond to zero) by k Signed: arithmetic shift Positive nmbers: div (division + rond to zero) by k Negative nmbers: div (division + rond away from zero) by k Use biasing to fix 5 Properties of Unsigned Arithmetic Unsigned Mltiplication with Addition Forms Commtative Ring Addition is commtative grop Closed nder mltiplication UMlt w (, v) w Mltiplication Commtative UMlt w (, v) UMlt w (v, ) Mltiplication is Associative UMlt w (t, UMlt w (, v)) UMlt w (UMlt w (t, ), v) is mltiplicative identity UMlt w (, ) Mltiplication distribtes over addtion UMlt w (t, UAdd w (, v)) UAdd w (UMlt w (t, ), UMlt w (t, v)) 7 Properties of Two s Comp. Arithmetic Isomorphic Algebras Unsigned mltiplication and addition Trncating to w bits Two s complement mltiplication and addition Trncating to w bits Both Form Rings Isomorphic to ring of integers mod w Comparison to (Mathematical) Integer Arithmetic Both are rings Integers obey ordering properties, e.g., > + v > v >, v > v > These properties are not obeyed by two s comp. arithmetic TMax + TMin 53 * 3-3 (-bit words) Why Shold I Use Unsigned? Conting Down with Unsigned Don t se withot nderstanding implications Easy to make mistakes nsigned i; for (i cnt-; i > ; i--) a[i] + a[i+]; Can be very sbtle #define DELTA sizeof(int) int i; for (i CNT; i-delta > ; i- DELTA)... 9 Proper way to se nsigned as loop index nsigned i; for (i cnt-; i < cnt; i--) a[i] + a[i+]; See Robert Seacord, Secre Coding in C and C++ C Standard garantees that nsigned addition will behave like modlar arithmetic UMax Even better size_t i; for (i cnt-; i < cnt; i--) a[i] + a[i+]; Data type size_t defined as nsigned vale with length word size Code will work even if cnt UMax What if cnt is signed and <? 9

15 Why Shold I Use Unsigned? (cont.) Today: Bits, Bytes, and Integers Do Use When Performing Modlar Arithmetic Mltiprecision arithmetic Do Use When Using Bits to Represent Sets Logical right shift, no sign extension Representing information as bits Bit-level maniplations Integers Representation: nsigned and signed Conversion, casting Expanding, trncating Addition, negation, mltiplication, shifting Smmary Representations in memory, pointers, strings 9 9 Byte-Oriented Memory Organization Machine Words Any given compter has a Word Size Nominal size of integer-valed data and of addresses Programs refer to data by address Conceptally, envision it as a very large array of bytes In reality, it s not, bt can think of it that way An address is like an index into that array and, a pointer variable stores an address Note: system provides private address spaces to each process Think of a process as a program being exected So, a program can clobber its own data, bt not that of others Until recently, most machines sed 3 bits ( bytes) as word size Limits addresses to GB ( 3 bytes) Increasingly, machines have -bit word size Potentially, cold have EB (exabytes) of addressable memory That s. X Machines still spport mltiple data formats Fractions or mltiples of word size Always integral nmber of bytes 93 9 Word-Oriented Memory Organization Example Data Representations Addresses Specify Byte Locations Address of first byte in word Addresses of sccessive words differ by (3-bit) or (-bit) 3-bit Words Addr?? Addr?? Addr?? Addr?? -bit Words Addr?? Addr?? Bytes Addr C Data Type Typical 3-bit Typical -bit x- char short int long float doble long doble / pointer 9 5

16 Byte Ordering Byte Ordering Example So, how are the bytes within a mlti-byte word ordered in memory? Conventions Big Endian: Sn, PPC Mac, Internet Example Variable x has -byte vale of x357 Address given by &x is x Least significant byte has highest address Little Endian: x, ARM processors rnning Android, ios, and Windows Least significant byte has lowest address Big Endian x x x x3 Little Endian x x x x Decimal: 53 Representing Integers Binary: Hex: Examining Data Representations 3 B D int A 53; IA3, x- D 3B Sn 3B D IA3 x- D 3B D 3B int B -53; IA3, x- 93 C FF FF Sn FF FF C 93 Code to Print Byte Representation of Data Casting pointer to nsigned char * allows treatment as a byte array long int C 53; Sn typedef nsigned char *pointer; 3B D void show_bytes(pointer start, size_t len){ size_t i; for (i ; i < len; i++) printf( %p\tx%.x\n",start+i, start[i]); printf("\n"); Printf directives: %p: Print pointer %x: Print hexadecimal Two s complement representation 99 show_bytes Exection Example Representing Pointers int B -53; int *P &B; int a 53; printf("int a 53;\n"); show_bytes((pointer) &a, sizeof(int)); Sn IA3 x- EF AC 3C FF B Reslt (Linx x-): FB F5 FE int a 53; x7fffb7f7dbc x7fffb7f7dbd x7fffb7f7dbe x7fffb7f7dbf C FF d 3b FD 7F Different compilers & machines assign different locations to objects Even get different reslts each time rn program

17 Representing Strings Reading Byte-Reversed Listings char S[] "3"; Strings in C Represented by array of characters Each character encoded in ASCII format IA3 Sn Standard 7-bit encoding of character set 3 3 Character has code x3 3 3 Digit i has code x3+i 3 3 String shold be nll-terminated 3 3 Final character Compatibility Byte ordering not an isse Disassembly Text representation of binary machine code Generated by program that reads the machine code Example Fragment Address Instrction Code Assembly Rendition 35: 5b pop %ebx 3: c3 ab add $xab,%ebx 3c: 3 bb cmpl $x,x(%ebx) Deciphering Nmbers Vale: xab Pad to 3 bits: xab Split into bytes: ab Reverse: ab 3 Integer C Pzzles Bons: More Integer C Pzzles. x < ((x*) < ). x > - 3. x > && y > x + y > Initialization. (x -x)>>3 - int x foo(); int y bar(); nsigned x x; nsigned y y; Initialization int x foo(); int y bar(); nsigned x x; nsigned y y; x < ((x*) < ) x > x & 7 7 (x<<3) < x > - x > y -x < -y x * x > x > && y > x + y > x > -x < x < -x > (x -x)>>3 - x >> 3 x/ x >> 3 x/ x & (x-)! 5 7

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary with contribtions from Dr. Bin Ren, College of William & Mary Addition, negation, mltiplication, shifting 1 Everything is bits The Decimal System and Bases Each bit is or 1 By encoding/interpreting sets

More information

Bits, Bytes, and Integer

Bits, Bytes, and Integer 19.3 Compter Architectre Spring 1 Bits, Bytes, and Integers Nmber Representations Bits, Bytes, and Integer Representing information as bits Bit-level maniplations Integers Representation: nsigned and signed

More information

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit Topics CISC3 Integers Sep 11, 28 Nmeric Encodings Unsigned & Twoʼs complement Programming Implications C promotion rles Basic operations Addition, negation, mltiplication Programming Implications Conseqences

More information

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers with contributions from Dr. Bin Ren, College of William & Mary 1 Bits, Bytes, and Integers Representing information as bits Bit-level manipulations Integers Representation: unsigned

More information

Bits, Bytes, and Integers Part 2

Bits, Bytes, and Integers Part 2 Bits, Bytes, and Integers Part 2 15-213: Introduction to Computer Systems 3 rd Lecture, Jan. 23, 2018 Instructors: Franz Franchetti, Seth Copen Goldstein, Brian Railing 1 First Assignment: Data Lab Due:

More information

CS140 Lecture 08: Data Representation: Bits and Ints. John Magee 13 February 2017

CS140 Lecture 08: Data Representation: Bits and Ints. John Magee 13 February 2017 CS140 Lecture 08: Data Representation: Bits and Ints John Magee 13 February 2017 Material From Computer Systems: A Programmer's Perspective, 3/E (CS:APP3e) Randal E. Bryant and David R. O'Hallaron, Carnegie

More information

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip!

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip! 15-13 The corse that gies CMU its Zip! Topics class3.ppt Integers Sep 3,! Nmeric Encodings " Unsigned & Two s complement! Programming Implications " C promotion rles! Basic operations " Addition, negation,

More information

Bits, Bytes, and Integers. Data Representa+on: Base- 2 number representa+on. Binary Representa+ons. Encoding Byte Values. Example Data Representa+ons

Bits, Bytes, and Integers. Data Representa+on: Base- 2 number representa+on. Binary Representa+ons. Encoding Byte Values. Example Data Representa+ons Bits, Bytes, and Data Representa+on: Bits, Bytes, and CSci 1 - Machine Architectre and Organiza+on Professor Pen- Chng Yew Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi9on,

More information

Lecture 5-6: Bits, Bytes, and Integers

Lecture 5-6: Bits, Bytes, and Integers CSCI-UA.0201-003 Computer Systems Organization Lecture 5-6: Bits, Bytes, and Integers Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Slides adapted from: Jinyang Li Bryant and O Hallaron

More information

Bits, Bytes, and Integers August 26, 2009

Bits, Bytes, and Integers August 26, 2009 15-213 The Class That Gives CMU Its Zip! Bits, Bytes, and Integers August 26, 2009 Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C Representations of Integers

More information

Computer Systems CEN591(502) Fall 2011

Computer Systems CEN591(502) Fall 2011 Computer Systems CEN591(502) Fall 2011 Sandeep K. S. Gupta Arizona State University 4 th lecture Data representation in computer systems (Slides adapted from CSAPP book) Announcements Programming assignment

More information

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 1 3: Integers in C Computer Architecture and Systems

More information

Integers. Today. Next time. ! Numeric Encodings! Programming Implications! Basic operations. ! Floats

Integers. Today. Next time. ! Numeric Encodings! Programming Implications! Basic operations. ! Floats Integers Today! Numeric Encodings! Programming Implications! Basic operations! Programming Implications Next time! Floats Fabián E. Bustamante, 2007 Integers in C! C supports several integral data types

More information

Page 1 CISC360. Encoding Integers Unsigned. Integers Sep 8, Numeric Ranges. Encoding Example (Cont.)

Page 1 CISC360. Encoding Integers Unsigned. Integers Sep 8, Numeric Ranges. Encoding Example (Cont.) CISC3 Integers Sep, 9 Encoding Integers Unsigned w 1 BU(X) = x i i i= short int x = 1513; short int y = -1513; Twoʼs Complement w BT(X) = x w 1 w 1 + x i i i= Sign Bit Decimal Hex Binary x 1513 3B D 11111

More information

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition Carnegie Mellon 1 Bits, Bytes and Integers Part 1 15-213/18-213/15-513: Introduction to Computer Systems 2 nd Lecture, Aug. 31, 2017 Today s Instructor: Randy Bryant 2 Announcements Recitations are on

More information

Integers. Dr. Steve Goddard Giving credit where credit is due

Integers. Dr. Steve Goddard   Giving credit where credit is due CSCE 23J Computer Organization Integers Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce23j Giving credit where credit is due Most of slides for this lecture are based on

More information

Integers Sep 3, 2002

Integers Sep 3, 2002 15-213 The course that gives CMU its Zip! Topics Numeric Encodings Unsigned & Two s complement Programming Implications C promotion rules Basic operations Integers Sep 3, 2002 Addition, negation, multiplication

More information

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition 1513 The corse that gies CMU its Zip! Integer Arithmetic Operations Jan. 5, 1 Topics Basic operations Addition, negation, mltiplication Programming Implications Conseqences of oerflow Using shifts to perform

More information

Systems 1. Integers. Unsigned & Twoʼs complement. Addition, negation, multiplication

Systems 1. Integers. Unsigned & Twoʼs complement. Addition, negation, multiplication Systems 1 Integers Topics Numeric Encodings Unsigned & Twoʼs complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication Programming Implications Consequences

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 3: Bits, Bytes, and Integers September 6, 2017 Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Bits, Bytes, Nibbles, Words and Strings Gal A. Kaminka galk@cs.biu.ac.il Topics Why bits? Why 0/1? Basic terms: Bits, Bytes, Nibbles, Words Representing information as bits Characters

More information

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2 ICS 2008 Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2 Data Representations Sizes of C Objects (in Bytes) C Data Type Compaq Alpha Typical 32-bit Intel IA32 int 4 4 4 long int 8 4 4

More information

Bits, Bytes and Integers Part 1

Bits, Bytes and Integers Part 1 Bits, Bytes and Integers Part 1 15-213/18-213/15-513: Introduction to Computer Systems 2 nd Lecture, Jan. 18, 2018 Instructors: Franz Franchetti Seth Copen Goldstein Brian Railing 1 Announcements Waitlist

More information

Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing

Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing Today s Topics Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing CSE351 Inaugural Edi7on Spring 2010 1 Encoding Integers C short

More information

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bit-level manipulations Boolean algebra Expressing

More information

Topics of this Slideset. CS429: Computer Organization and Architecture. Encoding Integers: Unsigned. C Puzzles. Integers

Topics of this Slideset. CS429: Computer Organization and Architecture. Encoding Integers: Unsigned. C Puzzles. Integers Topics of this Slideset CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Science University of Texas at Austin Last updated: July 5, 2018 at 11:55 Numeric Encodings:

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Science University of Texas at Austin Last updated: July 5, 2018 at 11:55 CS429 Slideset 3: 1 Topics of this Slideset

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides

More information

Bits, Bytes and Integers

Bits, Bytes and Integers Bits, Bytes and Integers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran

More information

Csci 2021 Class Web Pages. Data Representa?on: Bits, Bytes, and Integers. Binary Representa?ons. Bits, Bytes, and Integers

Csci 2021 Class Web Pages. Data Representa?on: Bits, Bytes, and Integers. Binary Representa?ons. Bits, Bytes, and Integers Csci 1 Class Web Pages Departmental Class Web Page: Pblic access withot login Corse syllabs, schedle, lectre notes, other sefl info h7p://www- sers.cselabs.mn.ed/classes/spring- 1/csci1/ Yo shold read

More information

Representing and Manipulating Integers. Jo, Heeseung

Representing and Manipulating Integers. Jo, Heeseung Representing and Manipulating Integers Jo, Heeseung Unsigned Integers Encoding unsigned integers B [ bw 1, bw 2,..., b0 ] x = 0000 0111 1101 0011 2 D( B) w 1 b i i 0 2 i D(x) = 2 10 + 2 9 + 2 8 + 2 7 +

More information

Bits and Bytes January 13, 2005

Bits and Bytes January 13, 2005 15-213 The Class That Gives CMU Its Zip! Topics Bits and Bytes January 13, 25 Why bits? Representing information as bits Binary / Hexadecimal Byte representations» Numbers» Characters and strings» Instructions

More information

CS 270: Computer Organization. Integer Arithmetic Operations

CS 270: Computer Organization. Integer Arithmetic Operations CS 270: Computer Organization Integer Arithmetic Operations Instructor: Professor Stephen P. Carl Unsigned Addition Operands: w bits True Sum: w+1 bits u + v u + v Discard Carry UAdd w (u, v) Standard

More information

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers CENG331 - Computer Organization Instructors: Murat Manguoglu (Section 1) Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Hello World! What happens under the hood?

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Boolean Algebra Developed by

More information

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 2 CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Numeric Ranges Unsigned Values UMin = 0 000 0 UMax = 2 w 1 111 1 Two s Complement

More information

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation Lecture 2 Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bit-level manipulations Boolean algebra

More information

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation Lecture 2 Bits and Bytes Topics! Why bits?! Representing information as bits " Binary/Hexadecimal " Byte representations» numbers» characters and strings» Instructions! Bit-level manipulations " Boolean

More information

Bits and Bytes: Data Presentation Mohamed Zahran (aka Z)

Bits and Bytes: Data Presentation Mohamed Zahran (aka Z) CSCI-UA.0201 Computer Systems Organization Bits and Bytes: Data Presentation Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted and modified from: Clark Barrett Jinyang

More information

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) Systems Software & Architecture Lab. Seoul National University Integers Spring 2019 4190.308: Computer Architecture Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) 2 A

More information

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers B&O Readings: 2.1-2.3 CSE 361: Introduc=on to Systems So@ware Instructor: I- Ting Angelina Le e Note: these slides were originally created by Markus Püschel at Carnegie Mellon

More information

BITS, BYTES, AND INTEGERS

BITS, BYTES, AND INTEGERS BITS, BYTES, AND INTEGERS CS 045 Computer Organization and Architecture Prof. Donald J. Patterson Adapted from Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition ORIGINS

More information

Integer Arithmetic. CS 347 Lecture 03. January 20, 1998

Integer Arithmetic. CS 347 Lecture 03. January 20, 1998 Integer Arithmetic CS 347 Lecture 03 January 20, 1998 Topics Numeric Encodings Unsigned & Two s complement Programming Implications C promotion rules Consequences of overflow Basic operations Addition,

More information

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10? Where Have We Been? Class Introduction Great Realities of Computing Int s are not Integers, Float s are not Reals You must know assembly Memory Matters Performance! Asymptotic Complexity It s more than

More information

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 2 CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Signed Integers Two s complement b w-1 = 0 Þ non-negative number value = b

More information

Hardware: Logical View

Hardware: Logical View Hardware: Logical View CPU Memory Bus Disks Net USB Etc. 1 Hardware: Physical View USB I/O controller Storage connections CPU Memory 2 Hardware: 351 View (version 0) instructions? Memory CPU data CPU executes

More information

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Byte Ordering Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Memory Model Physical memory DRAM chips can read/write 4, 8, 16 bits DRAM modules

More information

Manipulating Integers

Manipulating Integers Manipulating Integers Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Integer Encoding and Manipulation

Integer Encoding and Manipulation CSE 2421: Systems I Low-Level Programming and Computer Organization Integer Encoding and Manipulation Presentation D Study: Bryant Chapter 2.1 2.3 Gojko Babić 01-24-2018 Unsigned & Signed Integer Encoding

More information

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Byte Ordering Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Representing and Manipulating Integers Part I

Representing and Manipulating Integers Part I Representing and Manipulating Integers Part I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Introduction The advent of the digital age Analog

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 11, 2017 at 08:58 CS429 Slideset 2: 1 Topics of this Slideset

More information

Topics of this Slideset. CS429: Computer Organization and Architecture. It s Bits All the Way Down. Why Binary? Why Not Decimal?

Topics of this Slideset. CS429: Computer Organization and Architecture. It s Bits All the Way Down. Why Binary? Why Not Decimal? Topics of this Slideset CS429: Computer Organization and Architecture There are 10 kinds of people in the world: those who understand binary, and those who don t! Dr. Bill Young Department of Computer

More information

Representing Integers. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Representing Integers. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Representing Integers Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unsigned Integers Encoding unsigned integers B [ bw 1, bw2,..., b0 ] x = 0000

More information

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 1 CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Number Representation Hindu-Arabic numerals developed by Hindus starting in

More information

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15 Integer Representation Representation of integers: unsigned and signed Sign extension Arithmetic and shifting Casting But first, encode deck of cards. cards in suits How do we encode suits, face cards?

More information

CAPL Scripting Quickstart

CAPL Scripting Quickstart CAPL Scripting Qickstart CAPL (Commnication Access Programming Langage) For CANalyzer and CANoe V1.01 2015-12-03 Agenda Important information before getting started 3 Visal Seqencer (GUI based programming

More information

CSCI2467: Systems Programming Concepts

CSCI2467: Systems Programming Concepts CSCI2467: Systems Programming Concepts Slideset 2: Information as Data (CS:APP Chap. 2) Instructor: M. Toups Spring 2018 Course updates datalab out today! - due after Mardi gras... - do not wait until

More information

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up

More information

Representing Integers

Representing Integers Representing Integers Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

POWER-OF-2 BOUNDARIES

POWER-OF-2 BOUNDARIES Warren.3.fm Page 5 Monday, Jne 17, 5:6 PM CHAPTER 3 POWER-OF- BOUNDARIES 3 1 Ronding Up/Down to a Mltiple of a Known Power of Ronding an nsigned integer down to, for eample, the net smaller mltiple of

More information

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II. CSE 351 Autumn Instructor: Justin Hsia Integers II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/571/

More information

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II. CSE 351 Autumn Instructor: Justin Hsia Integers II CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/557/

More information

Memory, Data, & Addressing II CSE 351 Spring

Memory, Data, & Addressing II CSE 351 Spring Memory, Data, & Addressing II CSE 351 Spring 2018 http://xkcd.com/138/ Review Questions 1) If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) a) 64

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 3: OS model and Architectral Spport Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time/today

More information

CSE351: Memory, Data, & Addressing I

CSE351: Memory, Data, & Addressing I CSE351: Memory, Data, & Addressing I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis http://xkcd.com/138/

More information

Integers II. CSE 351 Autumn 2018

Integers II. CSE 351 Autumn 2018 Integers II CSE 351 Autumn 2018 Instructor: Teaching Assistants: Justin Hsia Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie Tian Teagan

More information

Review. How to represent real numbers

Review. How to represent real numbers PCWrite PC IorD Review ALUSrcA emread Address Write data emory emwrite em Data IRWrite [3-26] [25-2] [2-6] [5-] [5-] RegDst Read register Read register 2 Write register Write data RegWrite Read data Read

More information

CS367 Test 1 Review Guide

CS367 Test 1 Review Guide CS367 Test 1 Review Guide This guide tries to revisit what topics we've covered, and also to briefly suggest/hint at types of questions that might show up on the test. Anything on slides, assigned reading,

More information

The single-cycle design from last time

The single-cycle design from last time lticycle path Last time we saw a single-cycle path and control nit for or simple IPS-based instrction set. A mlticycle processor fies some shortcomings in the single-cycle CPU. Faster instrctions are not

More information

Simple Data Types in C. Alan L. Cox

Simple Data Types in C. Alan L. Cox Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

More information

Bitwise Data Manipulation. Bitwise operations More on integers

Bitwise Data Manipulation. Bitwise operations More on integers Bitwise Data Manipulation Bitwise operations More on integers bitwise operators ex Bitwise operators on fixed-width bit vectors. AND & OR XOR ^ NOT ~ 01101001 & 01010101 01000001 01101001 01010101 01101001

More information

EXAMINATIONS 2003 END-YEAR COMP 203. Computer Organisation

EXAMINATIONS 2003 END-YEAR COMP 203. Computer Organisation EXAINATIONS 2003 COP203 END-YEAR Compter Organisation Time Allowed: 3 Hors (180 mintes) Instrctions: Answer all qestions. There are 180 possible marks on the eam. Calclators and foreign langage dictionaries

More information

The final datapath. M u x. Add. 4 Add. Shift left 2. PCSrc. RegWrite. MemToR. MemWrite. Read data 1 I [25-21] Instruction. Read. register 1 Read.

The final datapath. M u x. Add. 4 Add. Shift left 2. PCSrc. RegWrite. MemToR. MemWrite. Read data 1 I [25-21] Instruction. Read. register 1 Read. The final path PC 4 Add Reg Shift left 2 Add PCSrc Instrction [3-] Instrction I [25-2] I [2-6] I [5 - ] register register 2 register 2 Registers ALU Zero Reslt ALUOp em Data emtor RegDst ALUSrc em I [5

More information

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION EXAINATIONS 2010 END OF YEAR COPUTER ORGANIZATION Time Allowed: 3 Hors (180 mintes) Instrctions: Answer all qestions. ake sre yor answers are clear and to the point. Calclators and paper foreign langage

More information

Putting the dynamic into software security testing

Putting the dynamic into software security testing Ptting the dynamic into software secrity testing Detecting and Addressing Cybersecrity Isses V1.1 2018-03-05 Code ahead! 2 Atomated vlnerability detection and triage + = 3 How did we get here? Vector was

More information

Review. A single-cycle MIPS processor

Review. A single-cycle MIPS processor Review If three instrctions have opcodes, 7 and 5 are they all of the same type? If we were to add an instrction to IPS of the form OD $t, $t2, $t3, which performs $t = $t2 OD $t3, what wold be its opcode?

More information

Review Multicycle: What is Happening. Controlling The Multicycle Design

Review Multicycle: What is Happening. Controlling The Multicycle Design Review lticycle: What is Happening Reslt Zero Op SrcA SrcB Registers Reg Address emory em Data Sign etend Shift left Sorce A B Ot [-6] [5-] [-6] [5-] [5-] Instrction emory IR RegDst emtoreg IorD em em

More information

The extra single-cycle adders

The extra single-cycle adders lticycle Datapath As an added bons, we can eliminate some of the etra hardware from the single-cycle path. We will restrict orselves to sing each fnctional nit once per cycle, jst like before. Bt since

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 11: Semaphores Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time Worked throgh software implementation

More information

REMEMBER TO REGISTER FOR THE EXAM.

REMEMBER TO REGISTER FOR THE EXAM. REMEMBER TO REGISTER FOR THE EXAM http://tenta.angstrom.uu.se/tenta/ Floating point representation How are numbers actually stored? Some performance consequences and tricks Encoding Byte Values Byte =

More information

Data III & Integers I

Data III & Integers I Data III & Integers I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Everyone has VM

More information

Lecture 7. Building A Simple Processor

Lecture 7. Building A Simple Processor Lectre 7 Bilding A Simple Processor Christos Kozyrakis Stanford University http://eeclass.stanford.ed/ee8b C. Kozyrakis EE8b Lectre 7 Annoncements Upcoming deadlines Lab is de today Demo by 5pm, report

More information

The multicycle datapath. Lecture 10 (Wed 10/15/2008) Finite-state machine for the control unit. Implementing the FSM

The multicycle datapath. Lecture 10 (Wed 10/15/2008) Finite-state machine for the control unit. Implementing the FSM Lectre (Wed /5/28) Lab # Hardware De Fri Oct 7 HW #2 IPS programming, de Wed Oct 22 idterm Fri Oct 2 IorD The mlticycle path SrcA Today s objectives: icroprogramming Etending the mlti-cycle path lti-cycle

More information

Data III & Integers I

Data III & Integers I Data III & Integers I CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun

More information

SIGNED AND UNSIGNED SYSTEMS

SIGNED AND UNSIGNED SYSTEMS EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find

More information

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems CS 153 Design of Operating Systems Spring 18 Lectre 25: Dynamic Memory (1) Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Some slides modified from originals

More information

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

More information

COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization. Data Representation COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

More information

Memory, Data, & Addressing II

Memory, Data, & Addressing II Memory, Data, & Addressing II CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 153 Design of Operating Systems Spring 18 Lectre 2: Historical Perspective Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time What is an OS?

More information

CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2015 Solutions CSE 351 Midterm - Winter 2015 Solutions February 09, 2015 Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

More information

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation

More information

Integer Representation Floating point Representation Other data types

Integer Representation Floating point Representation Other data types Chapter 2 Bits, Data Types & Operations Integer Representation Floating point Representation Other data types Why do Computers use Base 2? Base 10 Number Representation Natural representation for human

More information

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine Course overview Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18 with slides by Kip Irvine Logistics Meeting time: 9:10am-12:10pm, Monday Classroom: CSIE Room 102 Instructor: Yung-Yu

More information

Integer Representation

Integer Representation Integer Representation Representation of integers: unsigned and signed Modular arithmetic and overflow Sign extension Shifting and arithmetic Multiplication Casting 1 Fixed- width integer encodings Unsigned

More information

Dr Paolo Guagliardo. Fall 2018

Dr Paolo Guagliardo. Fall 2018 The NULL vale Dr Paolo Gagliardo dbs-lectrer@ed.ac.k Fall 2018 NULL: all-prpose marker to represent incomplete information Main sorce of problems and inconsistencies... this topic cannot be described in

More information

CS 251, Winter 2018, Assignment % of course mark

CS 251, Winter 2018, Assignment % of course mark CS 25, Winter 28, Assignment 3.. 3% of corse mark De onday, Febrary 26th, 4:3 P Lates accepted ntil : A, Febrary 27th with a 5% penalty. IEEE 754 Floating Point ( points): (a) (4 points) Complete the following

More information