!"#$%$&'(!"#$!%&!'#$(%)*+,-./0123/,*-/*4/561-7.*89:-75:* %.0 *;72-1.7<*!=*>?,1?.9*$=!=*

Size: px
Start display at page:

Download "!"#$%$&'(!"#$!%&!'#$(%)*+,-./0123/,*-/*4/561-7.*89:-75:* %.0 *;72-1.7<*!=*>?,1?.9*$=!=*"

Transcription

1 !"#$%$&'(!"#$!%&!'#$(%)*+,-./0123/,*-/*4/561-7.*89:-75:* %.0 -)#+./0(! -1$23#'(#+(423/4&(#5$(/)#+./0('6'#$2(! 7&/89:(+0'*$"49$'(

2 B/'#(C42$,(D4#'(E(D6#$'(! D4#':(D6#$':(F+&?'(! G$*42/.:(04"/&6:(5$H/?$*42/.(&$3&$'$"#/9+"(! I4&#)/.(2$2+&6('3/*$:(/??&$''4"%:(06#$(+&?$&4"%(! D++.$/"(/.%$0&/(! D4#(J$&')'(.+%4*/.(+3$&/9+"'(4"(<( C+?/6,(!"#$%$&'(! K$3&$'$"#/9+",()"'4%"$?(/"?('4%"$?(! <+"J$&'4+":(*/'9"%(! LH3/"?4"%:(#&)"*/9"%(! -??49+":("$%/9+":(2).93.4*/9+":('54M4"%(! N)22/&6(

3 L"*+?4"%(!"#$%$&'( P"'4%"$?( CQ+R'(<+23.$2$"#( short int x = 15213; short int y = ;! <(short(o(06#$'(.+"%( N4%"( D4#(! N4%"(D4#(! G/.*$H:*2/56B757,-<*5/:-*:AE,AI2?,-*JA-*A,0A2?-7:*:AE,*! =*K/.*,/,,7E?3L7*!!*K/.*,7E?3L7* L"*+?4"%(LH/23.$(><+"#SA( x = 15213: y = :

4 T)2$&4*(K/"%$'(! P"'4%"$?(I/.)$'(!!"#$ *M *=* ===N=*!!"%&* *M **$ ' *O*!*!!!N!*!(CQ+R'(<+23.$2$"#(I/.)$'(! ("#$ *M **O$ 'O!*!==N=*! ("%&* *M **$ 'O! *O*!* =!!N!*!(U#5$&(I/.)$'(! PA,1:*!*!!!N!* I/.)$'(=+&(!(V(WX( I/.)$'(=+&(G4Y$&$"#(F+&?(N4Z$'(! U0'$&J/9+"'(! Q("#$)Q* *M* *("%&*R*!*! S:9557-.A2*.?,E7*!!"%& *M *$*T*("%&*R*!**! <([&+%&/224"%(! UA,2B107*VBA5A-:WXY*! Z72B?.7:*2/,:-?,-:<*7WEW<*! [;\CD]PS^*! ;\CD]PS^*! ;\CD]P+C*! _?B17:*6B?`/.5*:672AI2 **

5 P"'4%"$?(E(N4%"$?(T)2$&4*(I/.)$'( *) DOP>#A( DOC>#A( ====* =* =* ===!*!*!* ==!=* $* $* ==!!* %* %* =!==* (* (* =!=!* "* "* =!!=* h* h* =!!!* i* i*!===* '* O'*!==!* j* Oi*!=!=*!=* Oh*!=!!*!!* O"*!!==*!$* O(*!!=!*!%* O%*!!!=*!(* O$*!!!!*!"* O!*! 8?57*7,2/0A,E:*K/.*,/,,7E?3L7* L?B17:*! al7.9*ja-*6?b7.,*.76.7:7,-:* 1,Ac17*A,-7E7.*L?B17*! a?2x*.76.7:7,-?jb7*a,-7e7.*x?:* 1,Ac17*JA-*7,2/0A,E*!!(</"(!"J$&#(\/334"%'(! #! A,-7E7.*! #! A,-7E7.* C+?/6,(!"#$%$&'(! K$3&$'$"#/9+",()"'4%"$?(/"?('4%"$?(! <+"J$&'4+":(*/'9"%(! LH3/"?4"%:(#&)"*/9"%(! -??49+":("$%/9+":(2).93.4*/9+":('54M4"%(! N)22/&6(

6 CQ+R'(<+23.$2$"#( P"'4%"$?( x! ux! X! \/334"%(D$#Q$$"(N4%"$?(E(P"'4%"$?( CQ+R'(<+23.$2$"#( P"'4%"$?( ux! x! X!! \/334"%'(0$$"()"'4%"$?(/"?(#Q+R'(*+23.$2$"#(")20$&',( (]$$3(04#(&$3&$'$"#/9+"'(/"?(&$4"#$&3&$#( \/334"%(N4%"$?("(P"'4%"$?( POC( COP(

7 \/334"%(N4%"$?("(P"'4%"$?( V( ^WX( K$./9+"(0$#Q$$"(N4%"$?(E(P"'4%"$?( CQ+R'(<+23.$2$"#( w 1! 0! ux! x! f$[* x! ux! X! P?A,-?A,*8?57*@A-*k?b7.,* P"'4%"$?( B/&%$("$%/9J$(Q$4%5#( +,-./,0) B/&%$(3+'49J$(Q$4%5#(

8 <+"J$&'4+"(I4')/.4Z$?(! OR'(<+23S(#(P"'4%"$?(! \.07.A,E*+,L7.:A/,*! ("%&) ("%&))R*!) ("%&) [,:AE,70* l?,e7* $H:*4/56B757,- *l?,e7* =* O!* O$* =* ("#$) N4%"$?(J'S(P"'4%"$?(4"(<(! [,:AE,70*AK*X?L7*m[n*?:*:1op* 0U, U! </'9"%(! ap6ba2a-*2?:3,e*j7-g77,*:ae,70*q*1,:ae,70*:?57*?:*[$f*?,0*f$[* int tx, ty; unsigned ux, uy; tx = (int) ux; uy = (unsigned) ty;! +56BA2A-*2?:3,E*?B:/*/221.:*LA?*?::AE,57,-:*?,0*6./2701.7*2?BB:* tx = ux; uy = ty;

9 </'9"%(N)&3&4'$'( *= 0 *=[ 0U ** == )"'4%"$? *#! -1 *= 0 ** < '4%"$? *#! -1 *=[ 0U ** > )"'4%"$? *$!(i('%h(i *#$!(i('%h(i#!* ** > '4%"$?( *$!(i('%h(i[ U *#$!(i('%h(i#!* ** < )"'4%"$? *#! -1 *#$* -2 ** > '4%"$? *d1,:ae,70e#! (unsigned) -1 *#$* -2 ** > )"'4%"$? **$!(i('%h(i* *$!(i('%h('[* U < ** )"'4%"$? **$!(i('%h(i* *da,-e*$!(i('%h('[* (int) U > '4%"$?! LH3&$''4+"(LJ/.)/9+"(! +K*-X7.7*A:*?*5Ap*/K*1,:AE,70*?,0*:AE,70*A,*:A,EB7*7p6.7::A/,<** $%&'()"*+,-($"%./,%0%1,2"0+$1"13"-'$%&'()"! +,2B10A,E*2/56?.A:/,*/67.?3/,:*<:(>:(==:(<=:(>=! ap?56b7:*k/.*1*m*%$)****c\!t(v(_o:w`a:`bc:x`b(:(((((c\-d(v(o:w`a:`bc:x`a(! <+"'#/"# W (<+"'#/"# O (K$./9+" (LJ/.)/9+"( <+?$(N$*)&4#6(LH/23.$( /* Kernel memory region holding user-accessible data */ #define KSIZE 1024 char kbuf[ksize]; /* Copy at most maxlen bytes from kernel region to user buffer */ int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len; }! N424./&(#+(*+?$(=+)"?(4"(e&$$DNGR'(423.$2$"#/9+"(+=( %$#3$$&"/2$(! C5$&$(/&$(.$%4+"'(+=('2/&#(3$+3.$(#&64"%(#+(f"?( J)."$&/04.49$'(4"(3&+%&/2'(

10 C634*/.(P'/%$( /* Kernel memory region holding user-accessible data */ #define KSIZE 1024 char kbuf[ksize]; /* Copy at most maxlen bytes from kernel region to user buffer */ int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len; } #define MSIZE 528 void getstuff() { char mybuf[msize]; copy_from_kernel(mybuf, MSIZE); printf( %s\n, mybuf); } \/.4*4+)'(P'/%$( /* Declaration of library function memcpy */ void *memcpy(void *dest, void *src, size_t n); /* Kernel memory region holding user-accessible data */ #define KSIZE 1024 char kbuf[ksize]; /* Copy at most maxlen bytes from kernel region to user buffer */ int copy_from_kernel(void *user_dest, int maxlen) { /* Byte count len is minimum of buffer size and maxlen */ int len = KSIZE < maxlen? KSIZE : maxlen; memcpy(user_dest, kbuf, len); return len; } #define MSIZE 528 void getstuff() { char mybuf[msize]; copy_from_kernel(mybuf, -MSIZE);... }

11 N)22/&6( </'9"%(N4%"$?(g(P"'4%"$?,(D/'4*(K).$'(! D4#(3/1$&"(4'(2/4"#/4"$?(! D)#(&$4"#$&3&$#$?(! </"(5/J$()"$H3$*#$?($Y$*#',(/??4"%(+&(')0#&/*9"%(O Q(! LH3&$''4+"(*+"#/4"4"%('4%"$?(/"?()"'4%"$?(4"#(! A,-*A:*2?:-*-/*1,:AE,70rr* C+?/6,(!"#$%$&'(! K$3&$'$"#/9+",()"'4%"$?(/"?('4%"$?(! <+"J$&'4+":(*/'9"%(! LH3/"?4"%:(#&)"*/9"%(! -??49+":("$%/9+":(2).93.4*/9+":('54M4"%(! N)22/&6(

12 N4%"(LH#$"'4+"(! C/'],(! DAL7,*'#JA-*:AE,70*A,-7E7.*&*! 4/,L7.-*A-*-/*'R2#JA-*A,-7E7.*gA-X*:?57*L?B17*! K).$,(! P?s7*2*2/6A7:*/K*:AE,*JA-)*! **$*M**& 'O!* <N<*& 'O!* <*& 'O!* <*& 'O$* <N<*& =* 4(*+34$'(+=(\ND( X % ') X $% 2) ') N4%"(LH#$"'4+"(LH/23.$( short int x = 15213; int ix = (int) x; short int y = ; int iy = (int) y; Decimal Hex Binary x B 6D ix B 6D y C iy FF FF C ! <+"J$&9"%(=&+2('2/..$&(#+(./&%$&(4"#$%$&(?/#/(#63$(! <(/)#+2/9*/..6(3$&=+&2'('4%"($H#$"'4+"(

13 N)22/&6,( LH3/"?4"%:(C&)"*/9"%,(D/'4*(K).$'(! LH3/"?4"%(>$S%S:('5+&#(4"#(#+(4"#A(! [,:AE,70)*t7./:*?0070*! C&)"*/9"%(>$S%S:()"'4%"$?(#+()"'4%"$?('5+&#A(! [,:AE,70&:AE,70)*JA-:*?.7*-.1,2?-70*! l7:1b-*.7a, *! [,:AE,70)*5/0*/67.?3/,*! 8AE,70)*:A5AB?.*-/*5/0*! G/.*:5?BB*,15J7.:*9A7B0:*7p672-70*J7X?LA/1.* C+?/6,(!"#$%$&'(! K$3&$'$"#/9+",()"'4%"$?(/"?('4%"$?(! <+"J$&'4+":(*/'9"%(! LH3/"?4"%:(#&)"*/9"%(! -??49+":("$%/9+":(2).93.4*/9+":('54M4"%(! N)22/&6(

14 T$%/9+",(<+23.$2$"#(E(!"*&$2$"#(! <./42,(e+..+Q4"%(h+.?'(=+&(OR'(<+23.$2$"#( ~x + 1 == -x! <+23.$2$"#(! \J:7.L?3/,)*~x + x == == -1 R* *p* up* #!*!*=*=*!*!*!*=*!* =*!*!* =*=* =*!*=*!*!*!*!*!*!*!*!*! <+23.$#$([&++=i <+23.$2$"#(E(!"*&$2$"#(LH/23.$'( H(V(WjOWc( H(V(k(

15 P"'4%"$?(-??49+"( \67.?,0:)*'*JA-:* f.17*815)*'r!*ja-:* ZA:2?.0*4?..9)*'*JA-:* u! +! v! u + v! UAdd w (u, v)!! N#/"?/&?(-??49+"(e)"*9+"(! +E,/.7:*2?..9*/1-61-*!!23.$2$"#'(\+?)./&(-&4#52$9*( 0 * *M **[S00 ' d3*<*4e *M* 3*R*4**5/0*$ ') I4')/.4Z4"%(>\/#5$2/9*/.A(!"#$%$&(-??49+"(!!"#$%$&(-??49+"(! (#JA-*A,-7E7.:*3<*4*! 4/561-7*-.17*:15* S00 ( d3*<*4e*! _?B17:*A,2.7?:7*BA,7?.B9* ga-x*3*?,0*4)! G/.5:*6B?,?.*:1.K?27* -??`>-(:(*A( *" -"

16 I4')/.4Z4"%(P"'4%"$?(-??49+"(! F&/3'(-&+)"?(! +K*-.17*:15*v*$ ' *! S-*5/:-*/,27* UJ$&l+Q( P-??`>-(:(*A( C&)$(N)2( $ 'R!* \L7.w/g* $ ') =* \+?)./&(N)2( -" *" \/#5$2/9*/.([&+3$&9$'(! \+?)./&(-??49+"(e+&2'(/"(56(,%+'"783-/(! <.+'$?*1,07.*?00A3/,* =**&*[S00 ' d3*<*4e***&**$ ' *O!*! <+22)#/9J$( [S00 ' d3*<*4e**m***[s00 ' d4*<*3e*! -''+*4/9J$( [S00 ' d5<*[s00 ' d3*<*4ee**m***[s00 ' d[s00 ' d5<*3*e<*4e*! k*a:*?00a3l7*a07,3-9* [S00 ' d3*<*=e**m**3*! al7.9*7b757,-*x?:*?00a3l7*4"j$&'$(! ;7-* *[4/56 ') d3*e**m*$ ' *O*3* [S00 ' d3*<*[4/56 ') d3*ee**m**=*

17 CQ+R'(<+23.$2$"#(-??49+"( \67.?,0:)*'*JA-:* f.17*815)*'r!*ja-:* ZA:2?.0*4?..9)*'*JA-:* u! + v! u + v! TAdd w (u, v)!! C-??(/"?(P-??(5/J$(!?$"9*/.(D4#_B$J$.(D$5/J4+&(! 8AE,70*L:W*1,:AE,70*?00A3/,*A,*4)* int s, t, u, v; s = (int) ((unsigned) u + (unsigned) v); t = u + v! xabb*eal7 s == t C-??(UJ$&l+Q(! e)"*9+"/.4#6(! f.17*:15*.7c1a.7:*'r!* JA-:*! Z./6*/y*P8@*! f.7?-*.75?a,a,e*ja-:*?:* $H:*2/56W*A,-7E7.* k*!!!n!* k*!==n=* k*===n=* C&)$(N)2( $ ' O!* $ ')O!* =* k/:\l7.* C-??(K$').#( =!!N!* ===N=* W*=!!N!* O$ ')O! O!*!==N=* W*===N=* O$ ') C7E\L7.*

18 I4')/.4Z4"%(OR'(<+23.$2$"#(-??49+"( T$%UJ$&(! I/.)$'(! (#JA-*-g/H:*2/56W*! l?,e7*k./5*#'*-/*ri*! F&/3'(-&+)"?(! +K*:15*'*$ 'O! S-*5/:-*/,27*! +K*:15*V*O$ 'O! S-*5/:-*/,27* -" C-??`>-(:(*A( *" [+'UJ$&( <5/&/*#$&4Z4"%(C-??(! e)"*9+"/.4#6(! f.17*:15*.7c1a.7:*'r!*ja-:*! f.7?-*.75?a,a,e*ja-:*?:*$h:* 2/56W*A,-7E7.* C-??>-(:(*A( Y*=* v V*=* C7E?3L7*\L7.w/g* V*=* u Y*=* k/:a3l7*\l7.w/g* 2 w >T$%UJ$&A( 2 w >[+'UJ$&A(

19 \/#5$2/9*/.([&+3$&9$'(+=(C-??(!!'+2+&354*(7&+)3(#+()"'4%"$?'(Q4#5(P-??(! fs00 ' d3*<*4e*m**[$fd[s00 ' df$[d3*e<*f$[d4eee*! 8A,27*J/-X*X?L7*A07,32?B*JA-*6?b7.,:*! CQ+R'(<+23.$2$"#(P"?$&(C-??(e+&2'(/(7&+)3(! 4B/:70<*4/551-?3L7<*S::/2A?3L7<*=*A:*?00A3L7*A07,3-9*! al7.9*7b757,-*x?:*?00a3l7*a,l7.:7* \).93.4*/9+"(! <+23)9"%(LH/*#([&+?)*#(+=('_04#(")20$&'(&:(6)! aa-x7.*:ae,70*/.*1,:ae,70*! K/"%$'"! [,:AE,70)*=*z*&*T*6*z*d$ ' *O*!e* $ **M**$ $' *O*$ 'R! *R*!*! [6*-/*$'*JA-:*! fg/h:*2/56b757,-*5a,)*&*t*6**v*do$ 'O! etd$ 'O! O!e**M**O$ $'O$* R*$ 'O!*! [6*-/*$'O!*JA-:*! fg/h:*2/56b757,-*5?p)*&*t*6*z*do$ 'O! e* $ **M**$ $'O$*! [6*-/*$'*JA-:<*J1-*/,B9*K/.*d("#$ ' e $*! \/4"#/4"4"%(LH/*#(K$').#'(! x/1b0*,770*-/*s776*7p6?,0a,e*g/.0*:at7*ga-x*7?2x*6./012-*2/561-70*! Z/,7*A,*:/{g?.7*J9*m?.JA-.?.9*6.72A:A/,n*?.A-X5732*6?2s?E7:*

20 P"'4%"$?(\).93.4*/9+"(4"(<( \67.?,0:)*'*JA-:* f.17*k./012-)*$t'**ja-:* ZA:2?.0*'*JA-:)*'*JA-:* u v! u! * v! UMult w (u, v)!! N#/"?/&?(\).93.4*/9+"(e)"*9+"(! +E,/.7:*XAEX*/.07.*'*JA-:*!!23.$2$"#'(\+?)./&(-&4#52$9*( [P1B- ' d3*<*4e *M *3*** *4**5/0*$ ') <+?$(N$*)&4#6(LH/23.$(mO(! NPT(dGK(.40&/&6(! xa07b9*1:70*baj.?.9*k/.*-.?,:k7..a,e*0?-?*j7-g77,*5?2xa,7:* void* copy_elements(void *ele_src[], int ele_cnt, size_t ele_size); ele_src 2/..+*>$.$n*"#(o($.$n'4Z$A(

21 dgk(<+?$( void* copy_elements(void *ele_src[], int ele_cnt, size_t ele_size) { /* * Allocate buffer for ele_cnt objects, each of ele_size bytes * and copy from locations designated by ele_src */ void *result = malloc(ele_cnt * ele_size); if (result == NULL) /* malloc failed */ return NULL; void *next = result; int i; for (i = 0; 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; } return result; } dgk(i)."$&/04.4#6( 2/..+*>$.$n*"#(o($.$n'4Z$A(! F5/#(4=,(! ele_cnt *M*$ $= *R*!*! ele_size* *M*(=jh* * *M*$!$*! SBB/2?3/, *M*}}*! h+q(*/"(!(2/]$(#54'(=)"*9+"('$*)&$i(

22 N4%"$?(\).93.4*/9+"(4"(<( \67.?,0:)*'*JA-:* f.17*k./012-)*$t'**ja-:* ZA:2?.0*'*JA-:)*'*JA-:* u v! u! * v! TMult w (u, v)!! N#/"?/&?(\).93.4*/9+"(e)"*9+"(! +E,/.7:*XAEX*/.07.*'*JA-:*! 8/57*/K*gXA2X*?.7*0Ay7.7,-*K/.*:AE,70* L:W*1,:AE,70*51B36BA2?3/,*! ;/g7.*ja-:*?.7*-x7*:?57* [+Q$&_+=_O(\).93.6(Q4#5(N54M(! U3$&/9+"(! u << k(eal7:*u * 9 \67.?,0:)*'*JA-:* f.17*k./012-)*'r2**ja-:* u 2 k!! LH/23.$'(! u << 3 == u * 8! u << 5 - u << 3 == u * 24! P/:-*5?2XA,7:*:XA{*?,0*?00*K?:-7.*-X?,*51B36B9*! 4/56AB7.*E7,7.?-7:*-XA:*2/07*?1-/5?32?BB9* * u! 2 k! ZA:2?.0*2)*JA-:)*'*JA-:* UMult w (u, 2 k )! TMult w (u, 2 k )! k!

23 <+234.$?(\).93.4*/9+"(<+?$( <(e)"*9+"( int mul12(int x) { return x*12; } <+234.$?(-&4#52$9*(U3$&/9+"'( leal (%eax,%eax,2), %eax sall $2, %eax LH3./"/9+"( t <- x+x*2 return t << 2;! <(*+234.$&(/)#+2/9*/..6(%$"$&/#$'('54Mp/??(*+?$(Q5$"( 2).93.64"%(06(*+"'#/"#( P"'4%"$?([+Q$&_+=_O(G4J4?$(Q4#5(N54M(! q)+9$"#(+=(p"'4%"$?(06([+q$&(+=(o(! u >> k(eal7:**((u / 9 4" ) "! [:7:*B/EA2?B*:XA{* k! u! \67.?,0:)* / 2 k! ZALA:A/,)** l7:1b-)* u / 2 k! ( u / 2 k )*

24 <+234.$?(P"'4%"$?(G4J4'4+"(<+?$( <(e)"*9+"( unsigned udiv8(unsigned x) { return x/8; } <+234.$?(-&4#52$9*(U3$&/9+"'( shrl $3, %eax LH3./"/9+"( # Logical shift return x >> 3;! P'$'(.+%4*/.('54M(=+&()"'4%"$?(! e+&(r/j/(p'$&'((! ;/EA2?B*:XA{*g.Ab7,*?:*>>> N4%"$?([+Q$&_+=_O(G4J4?$(Q4#5(N54M(! q)+9$"#(+=(n4%"$?(06([+q$&(+=(o(! x >> k(eal7:**((x / 9 4" ) "! [:7:*?.A-X5732*:XA{*! l/1,0:*g./,e*0a.723/,*gx7,*u < 0 \67.?,0:)* ZALA:A/,)** l7:1b-)* / x! 2 k! x / 2 k! RoundDown(x / 2 k )! 0 k!

25 <+&&$*#([+Q$&_+=_O(G4J4?$(! q)+9$"#(+=(t$%/9j$(t)20$&(06([+q$&(+=(o(! x?,-***(x / O 4" +((((dl/1,0*f/g?.0*=e*! 4/561-7*?:**(((x+O 4-1)/ O 4" )(! +,*4)*(x + (1<<k)-1) >> </'$(W,(T+(&+)"?4"%( ZALA07,0)* u! +2 k 1! ZALA:/.)** / 2 k! * u / 2 k +! :%+$%'&";+$"'3"(<(01" k! <+&&$*#([+Q$&_+=_O(G4J4?$(><+"#SA( </'$(O,(K+)"?4"%( ZALA07,0)* k! 1 x! +2 k 1! ZALA:/.)** / 2 k! * x / 2 k +! +,2.757,-70*J9*!* :%+$%'&"+))$"="13">'+,"8($-,1" +,2.757,-70*J9*!*

26 <+234.$?(N4%"$?(G4J4'4+"(<+?$( <(e)"*9+"( int idiv8(int x) { return x/8; } <+234.$?(-&4#52$9*(U3$&/9+"'( testl %eax, %eax js L4 L3: sarl $3, %eax ret L4: addl $7, %eax jmp L3 LH3./"/9+"( if x < 0 x += 7; # Arithmetic shift return x >> 3;! P'$'(/&4#52$9*('54M(=+&(4"#(! e+&(r/j/(p'$&'((! S.A-XW*:XA{*g.Ab7,*?:*>> -&4#52$9*,(D/'4*(K).$'(! -??49+",(! [,:AE,70&:AE,70)*C/.5?B*?00A3/,*K/BB/g70*J9*-.1,2?-7<* :?57*/67.?3/,*/,*JA-*B7L7B*! [,:AE,70)*?00A3/,*5/0*$ g*! P?-X75?32?B*?00A3/,*R*6/::AJB7*:1J-.?23/,*/K*$g*! 8AE,70)*5/0AI70*?00A3/,*5/0*$ g* d.7:1b-*a,*6./67.*.?,e7e *! P?-X75?32?B*?00A3/,*R*6/::AJB7*?00A3/,*/.*:1J-.?23/,*/K*$g*! \).93.4*/9+",(! [,:AE,70&:AE,70)*C/.5?B*51B36BA2?3/,*K/BB/g70*J9*-.1,2?-7<* :?57*/67.?3/,*/,*JA-*B7L7B*! [,:AE,70)*51B36BA2?3/,*5/0*$ g*! 8AE,70)*5/0AI70*51B36BA2?3/,*5/0*$ g* d.7:1b-*a,*6./67.*.?,e7e *

27 -&4#52$9*,(D/'4*(K).$'(! P"'4%"$?(4"#':(OR'(*+23.$2$"#(4"#'(/&$(4'+2+&354*(&4"%',( 4'+2+&354'2(V(*/'9"%(! B$M('54M(! [,:AE,70&:AE,70)*51B36BA2?3/,*J9*$ s*! SBg?9:*B/EA2?B*:XA{*! K4%5#('54M(! [,:AE,70)*B/EA2?B*:XA{<*0AL*d0ALA:A/,*R*./1,0*-/*t7./e*J9*$ s*! 8AE,70)*?.A-X5732*:XA{*! k/:a3l7*,15j7.:)*0al*d0ala:a/,*r*./1,0*-/*t7./e*j9*$ s*! C7E?3L7*,15J7.:)*0AL*d0ALA:A/,*R*./1,0*?g?9*K./5*t7./e*J9*$ s* [:7*JA?:A,E*-/*Ip* C+?/6,(!"#$%$&'(! K$3&$'$"#/9+",()"'4%"$?(/"?('4%"$?(! <+"J$&'4+":(*/'9"%(! LH3/"?4"%:(#&)"*/9"%(! -??49+":("$%/9+":(2).93.4*/9+":('54M4"%(! N)22/&6(

28 [&+3$&9$'(+=(P"'4%"$?(-&4#52$9*(! P"'4%"$?(\).93.4*/9+"(Q4#5(-??49+"(e+&2'( <+22)#/9J$(K4"%(! S00A3/,*A:*2/551-?3L7*E./16*! 4B/:70*1,07.*51B36BA2?3/,* =**&*[P1B- ' d3*<*4e**&**$ ' *O!*! P1B36BA2?3/,*4/551-?3L7* [P1B- ' d3*<*4e**m***[p1b- ' d4*<*3e*! P1B36BA2?3/,*A:*S::/2A?3L7* [P1B- ' d5<*[p1b- ' d3*<*4ee**m***[p1b- ' d[p1b- ' d5<*3*e<*4e*!!*a:*51b36ba2?3l7*a07,3-9* [P1B- ' d3*<*!e**m**3*! P1B36BA2?3/,*0A:-.AJ1-7:*/L7.*?003/,* [P1B- ' d5<*[s00 ' d3*<*4ee**m***[s00 ' d[p1b- ' d5<*3*e<*[p1b- ' d5<*4ee* [&+3$&9$'(+=(CQ+R'(<+23S(-&4#52$9*(!!'+2+&354*(-.%$0&/'(! [,:AE,70*51B36BA2?3/,*?,0*?00A3/,*! f.1,2?3,e*-/*'*ja-:*! fg/h:*2/56b757,-*51b36ba2?3/,*?,0*?00a3/,*! f.1,2?3,e*-/*'*ja-:*! D+#5(e+&2(K4"%'(! +:/5/.6XA2*-/*.A,E*/K*A,-7E7.:*5/0*$ ' *! +,-7E7.:*/J79*/.07.A,E*6./67.37:<*7WEW<* 3*Y*= *! *3*R*4*Y*4* 3*Y*=<*4*Y*= *! *3* *4*Y*=*! fx7:7*6./67.37:*?.7*,/-*/j7970*j9*-g/h:*2/56w*?.a-x5732* ("%& + 1 == ("#$ * == d!h#ja-*g/.0:e*

29 a?:9*-/*5?s7*5a:-?s7:* unsigned i; for (i = cnt-2; i >= 0; i--) a[i] += a[i+1];! 4?,*J7*L7.9*:1J-B7* #define DELTA sizeof(int) int i; for (i = CNT; i-delta >= 0; i-= DELTA)...!?3(P'$(F5$"([$&=+&24"%(\+?)./&(-&4#52$9*(! P1B36.72A:A/,*?.A-X5732*!?3(P'$(F5$"(P'4"%(D4#'(#+(K$3&$'$"#(N$#'(! ;/EA2?B*.AEX-*:XA{<*,/*:AE,*7p-7,:A/,*!"#$%$&(<([)ZZ.$'(!"49/.4Z/9+"( 4"#(H(V(=++>As( 4"#(6(V(0/&>As( )"'4%"$?()H(V(Hs( )"'4%"$?()6(V(6s( x < 0! ((x*2) < 0) ux >= 0 x & 7 == 7! (x<<30) < 0 ux > -1 x > y! -x < -y x * x >= 0 x > 0 && y > 0! x + y > 0 x >= 0! -x <= 0 x <= 0! -x >= 0 (x -x)>>31 == -1 ux >> 3 == ux/8 x >> 3 == x/8 x & (x-1)!= 0(

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

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

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

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

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

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

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

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

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

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

Course Overview. Jo, Heeseung

Course Overview. Jo, Heeseung Course Overview Jo, Heeseung Course Theme: Abstraction Is Good But Don't Forget Reality Most CS and CE courses emphasize abstraction Abstract data types Asymptotic analysis These abstractions have limits

More information

1/%*2.&34.&%56+74.&%*8"(%&,.9%*!"#$%&'()*)+,'-.&.' & /* '012*)314'-5'"16*1+713'

1/%*2.&34.&%56+74.&%*8(%&,.9%*!#$%&'()*)+,'-.&.' & /* '012*)314'-5'16*1+713' 1/%*2.&34.&%56+74.&%*8"(%&,.9%*!"#$%&'()*)+,'-.&.' & /* '012*)314'-5'"16*1+713' 8"'(&:9(+&;'' 89:';13

More information

University*of*Washington*

University*of*Washington* Roadmap C: car c = malloc(sizeof(car)); c->miles = 1; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp %rbp

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

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

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

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

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

Course Overview. CSCI 224 / ECE 317: Computer Architecture. Instructors: Prof. Jason Fritts. Slides adapted from Bryant & O Hallaron s slides

Course Overview. CSCI 224 / ECE 317: Computer Architecture. Instructors: Prof. Jason Fritts. Slides adapted from Bryant & O Hallaron s slides Course Overview CSCI 224 / ECE 317: Computer Architecture Instructors: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Overview Course theme Five realities Logistics 2 Course Theme:

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

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

CS241 Computer Organization Spring

CS241 Computer Organization Spring CS241 Computer Organization Spring 2015 Prof. Searleman jets@clarkson.edu http://www.clarkson.edu/~jets/cs241 ! Name (as you like to be called)! Major! Graduating Year! Hometown! Programming & 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

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

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final Spring 2012 Name: Page Points Score 1 14 2 7 3 6 4 5 5 5 6 5 7 10 8 11 9 10 10 9 11 8 12 10 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc.

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

Process Layout, Function Calls, and the Heap

Process Layout, Function Calls, and the Heap Process Layout, Function Calls, and the Heap CS 6 Spring 20 Prof. Vern Paxson TAs: Devdatta Akhawe, Mobin Javed, Matthias Vallentin January 9, 20 / 5 2 / 5 Outline Process Layout Function Calls The Heap

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

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

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

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

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

1 /* file cpuid2.s */ 4.asciz The processor Vendor ID is %s \n 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start. 1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer,

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

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

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

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

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

CS , Fall 2001 Exam 1

CS , Fall 2001 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2001 Exam 1 October 9, 2001 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write

More information

Sungkyunkwan University

Sungkyunkwan University - 2 - Complete addressing mode, address computation (leal) Arithmetic operations Control: Condition codes Conditional branches While loops - 3 - Most General Form D(Rb,Ri,S) Mem[ Reg[ R b ] + S Reg[ R

More information

Overview. Course Overview and Introduction

Overview. Course Overview and Introduction Here early? Try going to http://chimein.cla.umn.edu/ and see if you can answer an ice cream question Course Overview and Introduction CSci 2021: Machine Architecture and Organization Lecture #1, September

More information

!"#$%&!'#($%&)*+&,*#(-(.$ /0+)'1&!"#$%&!'#($%&)*+&,*#(-(.$

!#$%&!'#($%&)*+&,*#(-(.$ /0+)'1&!#$%&!'#($%&)*+&,*#(-(.$ !"#$%&!'#($%&)*+&,*#(-(.$!"#$%&'()*+,-./01-*(+-(!-23/+4,("56+426 $ *+ (740+/,4!"#$%&&#"'( 89-2:6(!;(

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

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

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

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

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

Machine-Level Programming II: Control and Arithmetic

Machine-Level Programming II: Control and Arithmetic Machine-Level Programming II: Control and Arithmetic CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides 1 Today Complete addressing mode, address

More information

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes Machine-Level Programming II: Arithmetic & Control CS-281: Introduction to Computer Systems Instructor: Thomas C. Bressoud 1 Complete Memory Addressing Modes Most General Form D(Rb,Ri,S)Mem[Reg[Rb]+S*Reg[Ri]+

More information

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 n Mello Machine-Level Programming II: Arithmetic & Control 15-213/18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 Instructors: Gregory Kesden The course that gives CMU its Zip! Last Time:

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

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 Name Score out of 70 UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For TRUE/FALSE questions, write the

More information

Computer Systems Programming. Practice Midterm. Name:

Computer Systems Programming. Practice Midterm. Name: Computer Systems Programming Practice Midterm Name: 1. (4 pts) (K&R Ch 1-4) What is the output of the following C code? main() { int i = 6; int j = -35; printf( %d %d\n,i++, ++j); i = i >

More information

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

Today: Bits, Bytes, and Integers. Bits, Bytes, and Integers. For example, can count in binary. Everything is bits. Encoding Byte Values 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

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

Data Representation and Storage. Some definitions (in C)

Data Representation and Storage. Some definitions (in C) Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use pointer arithmetic correctly Explain

More information

Assembly Language: IA-32 Instructions

Assembly Language: IA-32 Instructions Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change

More information

SPAREPARTSCATALOG: CONNECTORS SPARE CONNECTORS KTM ART.-NR.: 3CM EN

SPAREPARTSCATALOG: CONNECTORS SPARE CONNECTORS KTM ART.-NR.: 3CM EN SPAREPARTSCATALOG: CONNECTORS ART.-NR.: 3CM3208201EN CONTENT SPARE CONNECTORS AA-AN SPARE CONNECTORS AO-BC SPARE CONNECTORS BD-BQ SPARE CONNECTORS BR-CD 3 4 5 6 SPARE CONNECTORS CE-CR SPARE CONNECTORS

More information

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11 ... 1/16 CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11 Alice E. Fischer February 3, 2016 ... 2/16 Outline Basic Types and Diagrams ... 3/16 Basic Types and Diagrams Types in C C has

More information

Assembly I: Basic Operations. Jo, Heeseung

Assembly I: Basic Operations. Jo, Heeseung Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

SPARE CONNECTORS KTM 2014

SPARE CONNECTORS KTM 2014 SPAREPARTSCATALOG: // ENGINE ART.-NR.: 3208201EN CONTENT CONNECTORS FOR WIRING HARNESS AA-AN CONNECTORS FOR WIRING HARNESS AO-BC CONNECTORS FOR WIRING HARNESS BD-BQ CONNECTORS FOR WIRING HARNESS BR-CD

More information

Credits to Randy Bryant & Dave O Hallaron

Credits to Randy Bryant & Dave O Hallaron Mellon Machine Level Programming II: Arithmetic & Control Lecture 4, March 10, 2011 Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Today Complete addressing mode, address

More information

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )

More information

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm

More information

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012 19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages

More information

Programming refresher and intro to C programming

Programming refresher and intro to C programming Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2

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

CPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b

CPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b CPSC 213 Introduction to Computer Systems Unit 1b Static Scalars and Arrays 1 Reading for Next 3 Lectures Companion 2.4.1-2.4.3 Textbook Array Allocation and Access 3.8 2 The Big Picture Build machine

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 3843 Final Exam Fall 2012

CS 3843 Final Exam Fall 2012 CS 3843 Final Exam Fall 2012 Name (Last), (First) ID Please indicate your session: Morning Afternoon You may use a calculator and two sheets of notes on this exam, but no other materials and no computer.

More information

Computer Organization & Systems Exam I Example Questions

Computer Organization & Systems Exam I Example Questions Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C

More information

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures 1 X86 Assembly Language and C Fundamentals Chapter 5 Data Transfer Instructions X86 Code Figures 2 Page 200, Figure 5.4 ;swap_bytes.asm ;-----------------------------------------------------------.STACK

More information

CS , Spring 2004 Exam 1

CS , Spring 2004 Exam 1 Andrew login ID: Full Name: CS 15-213, Spring 2004 Exam 1 February 26, 2004 Instructions: Make sure that your exam is not missing any sheets (there should be 15), then write your full name and Andrew login

More information

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics.

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics. Lecture 6B Machine-Level Programming V: Miscellaneous Topics Topics Linux Memory Layout Understanding Pointers Buffer Overflow Upper 2 hex digits of address Red Hat v. 6.2 ~1920MB memory limit FF C0 Used

More information

Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday

Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday addl: bitwise for signed (& unsigned) 4 bits: 1000 = -8, 0111 = 7-8 + -8 = -16 = 0 1000 + 1000

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

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming I: Introduction Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created

More information

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17 Arrays Young W. Lim 2017-02-06 Mon Young W. Lim Arrays 2017-02-06 Mon 1 / 17 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-06 Mon 2 / 17 Based on "Self-service Linux: Mastering

More information

CS , Fall 2004 Exam 1

CS , Fall 2004 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2004 Exam 1 Tuesday October 12, 2004 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front.

More information

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) (252-0061-00) Timothy Roscoe Herbstsemester 2013 Systems Group Department of Computer Science ETH Zürich 1 1: Introduction 252-0061-00, Herbstsemester 2013 Timothy Roscoe 2 This course covers in depth

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2017 Instructor: Justin Hsia 2017-10-30 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I

More information

CS61, Fall 2012 Midterm Review Section

CS61, Fall 2012 Midterm Review Section CS61, Fall 2012 Midterm Review Section (10/16/2012) Q1: Hexadecimal and Binary Notation - Solve the following equations and put your answers in hex, decimal and binary. Hexadecimal Decimal Binary 15 +

More information

Full Name: CISC 360, Fall 2008 Example of Exam

Full Name: CISC 360, Fall 2008 Example of Exam Full Name: CISC 360, Fall 2008 Example of Exam Page 1 of 0 Problem 1. (12 points): Consider the following 8-bit floating point representation based on the IEEE floating point format: There is a sign bit

More information

CS241 Computer Organization Spring Data Alignment

CS241 Computer Organization Spring Data Alignment CS241 Computer Organization Spring 2015 Data Alignment 3-26 2015 Outline! Data Alignment! C: pointers to functions! Memory Layout Read: CS:APP2 Chapter 3, sections 3.8-3.9 Quiz next Thursday, April 2nd

More information

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

So far, system calls have had easy syntax. Integer, character string, and structure arguments. Pointers Page 1 So far, system calls have had easy syntax Wednesday, September 30, 2015 10:45 AM Integer, character string, and structure arguments. But this is not always true. Today, we begin to explore

More information

CS , Fall 2002 Exam 1

CS , Fall 2002 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2002 Exam 1 October 8, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron

More information

Machine Level Programming II: Arithmetic &Control

Machine Level Programming II: Arithmetic &Control Machine Level Programming II: Arithmetic &Control Arithmetic operations Control: Condition codes Conditional branches Loops Switch Kai Shen 1 2 Some Arithmetic Operations Two Operand Instructions: Format

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19 Arrays Young W. Lim 2017-02-08 Wed Young W. Lim Arrays 2017-02-08 Wed 1 / 19 Outline 1 Introduction References Array Background Young W. Lim Arrays 2017-02-08 Wed 2 / 19 Based on "Self-service Linux: Mastering

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

CS241 Computer Organization Spring Addresses & Pointers

CS241 Computer Organization Spring Addresses & Pointers CS241 Computer Organization Spring 2015 Addresses & Pointers 2-24 2015 Outline! Addresses & Pointers! leal - load effective address! Condition Codes & Jumps! conditional statements: if-then-else! conditional

More information

Representation of Information

Representation of Information Representation of Information CS61, Lecture 2 Prof. Stephen Chong September 6, 2011 Announcements Assignment 1 released Posted on http://cs61.seas.harvard.edu/ Due one week from today, Tuesday 13 Sept

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security

CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 5 Readings 2 Secure Coding String management Pointer Subterfuge

More information

Characters, Character Strings, and string-manipulation functions in C

Characters, Character Strings, and string-manipulation functions in C Characters, Character Strings, and string-manipulation functions in C see Kernighan & Ritchie Section 1.9, Appendix B3 Characters Printable characters (and some non-printable ones) are represented as 8-bit

More information

CSCI 192 Engineering Programming 2. Assembly Language

CSCI 192 Engineering Programming 2. Assembly Language CSCI 192 Engineering Programming 2 Week 5 Assembly Language Lecturer: Dr. Markus Hagenbuchner Slides by: Igor Kharitonenko and Markus Hagenbuchner Room 3.220 markus@uow.edu.au UOW 2010 24/08/2010 1 C Compilation

More information

Datorarkitektur, 2009 Tentamen

Datorarkitektur, 2009 Tentamen Namn: Personnummer: Datorarkitektur, 2009 Tentamen 2009-03-13 Instructions: Make sure that your exam is not missing any sheets, then write your full name on the front. Write your answers in the space provided

More information