【正文】
above largest norm Denormalized numbers Normalized numbers RoundToEven Binary Fractional Numbers ? ―Even‖ when least significant bit is 0 ? Half way when bits to right of rounding position = 100…2 Examples ? Round to nearest 1/4 (2 bits right of binary point) Value Binary Rounded Action Rounded Value 2 3/32 (1/2—down) 2 2 3/16 (1/2—up) 2 1/4 2 7/8 (1/2—up) 3 2 5/8 (1/2—down) 2 1/2 Floating Point in C C Guarantees Two Levels float single precision double double precision Conversions ? Casting between int, float, and double changes numeric values ? Double or float to int ? Truncates fractional part ? Like rounding toward zero ? Not defined when out of range or NaN 187。 double d = …。 movl %eax,(%edx) *p = temp。 ?Computing arithmetic expressions of the form x + k*y ? k = 1, 2, 4, or 8. %rax %rdx %rcx %rbx %rsi %rdi %rsp %rbp x8664 General Purpose Registers ? Extend existing registers. Add 8 new ones. ? Make %ebp/%rbp general purpose %eax %edx %ecx %ebx %esi %edi %esp %ebp %r8 %r9 %r10 %r11 %r12 %r13 %r14 %r15 %r8d %r9d %r10d %r11d %r12d %r13d %r14d %r15d Swap in 64bit Mode ? Operands passed in registers ? First (xp) in %rdi, second (yp) in %rsi ? 64bit pointers ? No stack operations required ? 32bit data ? Data held in registers %eax and %edx ? movl operation void swap(int *xp, int *yp) { int t0 = *xp。 } swap: movl (%rdi), %edx movl (%rsi), %eax movl %eax, (%rdi) movl %edx, (%rsi) retq Reading Condition Codes SetX Condit ion Descri pti onsete ZF Equa l / Ze rosetne ~ZF N ot E qua l / N o t Zerosets SF N eg a t iv esetns ~SF N onnegat iv esetg ~(SF^OF)amp。 } else { result = yx。 } else { result = yx。 Update ) Body Init。 loop: Body Update 。 do { Body Update 。 while (Test ) { Body Update 。 middle: if (Test) goto loop。 *xp = loc[1]。 a[i+1] */ void swap_ele_se (long a[], int i) { swap(amp。 } swap_ele_se: movslq %esi,%rsi Sign extend i leaq (%rdi,%rsi,8), %rdi amp。 /* Swap a[i] amp。 } swap_ele: movslq %esi,%rsi Sign extend i leaq (%rdi,%rsi,8), %rdi amp。 operated on in floating point registers Intel GAS Bytes C Single s 4 float Double l 8 double Extended t 10/12/16 long double Array Allocation Basic Principle T A[L]。 A+i*C*4 A+(R1)*C*4 ? ? ? Nested Array Element Access Array Elements ? A[i][j] is element of type T ? Address A + i * (C * K) + j * K = A + (i * C + j)* K ? ? ? A [i] [j] A [i] [j] ? ? ? A[i] A [R1] [0] A [R1] [C1] ? ? ? A[R1] ? ? ? A A [0] [0] A [0] [C1] ? ? ? A[0] int A[R][C]。 } 361601656164168univcmu1 5 2 1 316 20 24 28 32 36mit0 2 1 3 936 40 44 48 52 56ucb9 4 7 2 056 60 64 68 72 7676 96 116 136 1561 5 2 0 6 1 5 2 1 3 1 5 2 1 7 1 5 2 2 1Using Nested Arrays Strengths ? C piler handles doubly subscripted arrays ? Generates very efficient code ? Avoids multiply in index putation Limitation ? Only works if have fixed array size define N 16 typedef int fix_matrix[N][N]。 j N。 } int var_ele (int *a, int i, int j, int n) { return a[i*n+j]。 j n。 int result = 0。 j n。 } struct S1 { char c。 Satisfying Alignment with Structures Offsets Within Structure ? Must satisfy element’s alignment requirement Overall Structure Placement ? Each structure has alignment requirement K ? Largest alignment of any element ? Initial address amp。lowest 2 bits of address must be 002 187。 Linux: 187。 int i[2]。 int i[2]。 strings declared in code Text ? Executable machine instructions ? Readonly Upper 2 hex digits of address BF 00 Stack Text Data Heap 08 C pointer declarations int *p p is a pointer to int int *p[13] p is an array[13] of pointer to int int *(p[13]) p is an array[13] of pointer to int int **p p is a pointer to a pointer to an int int (*p)[13] p is a pointer to an array[13] of int int *f() f is a function returning a pointer to int int (*f)() f is a pointer to a function returning int int (*(*f())[13])() f is a function returning ptr to an array[13] of pointers to functions returning int int (*(*x[3])())[5] x is an array[3] of pointers to functions returning pointers to array[5] of ints Malicious Use of Buffer Overflow ? Input