Lecture Slides 04 043 x86 Address Comp
Lecture Slides 04 043 x86 Address Comp
x86
University of Washington
Uses
Computing addresses without a memory reference
E.g., translation of p = &x[i];
Computing arithmetic expressions of the form x + k*i
k = 1, 2, 4, or 8
x86
University of Washington
x86
University of Washington
idivl, divl
x86
University of Washington
x86
University of Washington
Understanding arith
int arith
•
(int x, int y, int z) Stack
•
{
Offset •
int t1 = x+y;
int t2 = z+t1; 16 z
int t3 = x+4;
12 y
int t4 = y * 48;
int t5 = t3 + t4; 8 x
int rval = t2 * t5; 4 Rtn adr
return rval;
} 0 Old %ebp %ebp
Understanding arith
int arith
•
(int x, int y, int z) Stack
•
{
Offset •
int t1 = x+y;
int t2 = z+t1; 16 z
int t3 = x+4;
12 y
int t4 = y * 48;
int t5 = t3 + t4; 8 x
int rval = t2 * t5; 4 Rtn adr
return rval;
} 0 Old %ebp %ebp
Understanding arith
int arith
•
(int x, int y, int z) Stack
•
{
Offset •
int t1 = x+y;
int t2 = z+t1; 16 z
int t3 = x+4;
12 y
int t4 = y * 48;
int t5 = t3 + t4; 8 x
int rval = t2 * t5; 4 Rtn adr
return rval;
} 0 Old %ebp %ebp
Understanding arith
int arith
•
(int x, int y, int z) Stack
•
{
Offset •
int t1 = x+y;
int t2 = z+t1; 16 z
int t3 = x+4;
12 y
int t4 = y * 48;
int t5 = t3 + t4; 8 x
int rval = t2 * t5; 4 Rtn adr
return rval;
} 0 Old %ebp %ebp
Another Example
logical:
int logical(int x, int y) pushl %ebp Set
{ movl %esp,%ebp Up
int t1 = x^y;
int t2 = t1 >> 17; movl 8(%ebp),%eax
int mask = (1<<13) - 7; xorl 12(%ebp),%eax
int rval = t2 & mask; sarl $17,%eax
return rval; andl $8185,%eax
} Body
movl %ebp,%esp
popl %ebp Finish
ret
Stack
movl 8(%ebp),%eax # eax = x •
Offset
•
xorl 12(%ebp),%eax # eax = x^y •
sarl $17,%eax # eax = t1>>17
12 y
andl $8185,%eax # eax = t2 & 8185 8 x
4 Rtn adr
0 Old %ebp %ebp
x86
University of Washington
Another Example
logical:
int logical(int x, int y) pushl %ebp Set
{ movl %esp,%ebp Up
int t1 = x^y;
int t2 = t1 >> 17; movl 8(%ebp),%eax
int mask = (1<<13) - 7; xorl 12(%ebp),%eax
int rval = t2 & mask; sarl $17,%eax
return rval; andl $8185,%eax
} Body
movl %ebp,%esp
popl %ebp Finish
ret
x86
University of Washington
Another Example
logical:
int logical(int x, int y) pushl %ebp Set
{ movl %esp,%ebp Up
int t1 = x^y;
int t2 = t1 >> 17; movl 8(%ebp),%eax
int mask = (1<<13) - 7; xorl 12(%ebp),%eax
int rval = t2 & mask; sarl $17,%eax
return rval; andl $8185,%eax
} Body
movl %ebp,%esp
popl %ebp Finish
ret
x86
University of Washington
Another Example
logical:
int logical(int x, int y) pushl %ebp Set
{ movl %esp,%ebp Up
int t1 = x^y;
int t2 = t1 >> 17; movl 8(%ebp),%eax
int mask = (1<<13) - 7; xorl 12(%ebp),%eax
int rval = t2 & mask; sarl $17,%eax
return rval; andl $8185,%eax
} Body
movl %ebp,%esp
213 = 8192, 213 – 7 = 8185 popl %ebp Finish
…0010000000000000, …0001111111111001 ret
x86