Beruflich Dokumente
Kultur Dokumente
Arithmetic operations
swap:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
Set
Up
Body
Finish
Understanding Swap
void swap(int *xp, int *yp)
{
int t0 = *xp;
int t1 = *yp;
*xp = t1;
*yp = t0;
}
Offset
Stack
12
yp
xp
Rtn adr
0 Old %ebp
Register
%ecx
%edx
%eax
%ebx
Variable
yp
xp
t1
t0
%ebp
-4 Old %ebx
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
4
Address
Understanding Swap
123
0x124
456
0x120
0x11c
%eax
0x118
Offset
%edx
%ecx
%ebx
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
5
Address
Understanding Swap
123
0x124
456
0x120
0x11c
%eax
0x118
Offset
%edx
%ecx
0x120
%ebx
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
6
Address
Understanding Swap
123
0x124
456
0x120
0x11c
%eax
0x118
%edx
0x124
%ecx
0x120
Offset
%ebx
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
7
Address
Understanding Swap
123
0x124
456
0x120
0x11c
%eax
456
%edx
0x124
%ecx
0x120
0x118
Offset
%ebx
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
8
Address
Understanding Swap
123
0x124
456
0x120
0x11c
%eax
456
%edx
0x124
%ecx
0x120
%ebx
0x118
Offset
123
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
9
Address
Understanding Swap
456
0x124
456
0x120
0x11c
%eax
456
%edx
0x124
%ecx
0x120
%ebx
0x118
Offset
123
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
10
Address
Understanding Swap
456
0x124
123
0x120
0x11c
%eax
456
%edx
0x124
%ecx
0x120
%ebx
0x118
Offset
123
%esi
12
0x120
0x110
xp
0x124
0x10c
Rtn adr
0x108
0x104
-4
%esp
%ebp
yp
%ebp
%edi
0x114
0x104
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
#
#
#
#
#
#
ecx
edx
eax
ebx
*xp
*yp
0x100
=
=
=
=
=
=
yp
xp
*yp (t1)
*xp (t0)
eax
ebx
11
Mem[Reg[Rb]+S*Reg[Ri]+ D]
D:
S:
Scale: 1, 2, 4, or 8
Special Cases
(Rb,Ri)
Mem[Reg[Rb]+Reg[Ri]]
D(Rb,Ri)
Mem[Reg[Rb]+Reg[Ri]+D]
(Rb,Ri,S)
Mem[Reg[Rb]+S*Reg[Ri]]
12
0x100
Expression
Computation
Address
0x8(%edx)
0xf000 + 0x8
0xf008
(%edx,%ecx)
0xf000 + 0x100
0xf100
(%edx,%ecx,4)
0xf000 + 4*0x100
0xf400
0x80(,%edx,2)
2*0xf000 + 0x80
0x1e080
13
Uses
14
Computation
subl Src,Dest
imull Src,Dest
sall Src,Dest
sarl Src,Dest
shrl Src,Dest
xorl Src,Dest
andl Src,Dest
orl
Src,Dest
15
Computation
Dest = Dest + 1
decl Dest
Dest = Dest - 1
negl Dest
Dest = - Dest
notl Dest
Dest = ~ Dest
16
arith:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl 12(%ebp),%edx
leal (%edx,%eax),%ecx
leal (%edx,%edx,2),%edx
sall $4,%edx
addl 16(%ebp),%ecx
leal 4(%edx,%eax),%eax
imull %ecx,%eax
movl %ebp,%esp
popl %ebp
ret
Set
Up
Body
Finish
17
Understanding arith
int arith
(int x, int y, int z)
{
int t1 = x+y;
int t2 = z+t1;
int t3 = x+4;
int t4 = y * 48;
int t5 = t3 + t4;
int rval = t2 * t5;
return rval;
}
movl 8(%ebp),%eax
movl 12(%ebp),%edx
leal (%edx,%eax),%ecx
leal (%edx,%edx,2),%edx
sall $4,%edx
addl 16(%ebp),%ecx
leal 4(%edx,%eax),%eax
imull %ecx,%eax
#
#
#
#
#
#
#
#
Offset
16
12
Rtn adr
0 Old %ebp
eax
edx
ecx
edx
edx
ecx
eax
eax
=
=
=
=
=
=
=
=
x
y
x+y (t1)
3*y
48*y (t4)
z+t1 (t2)
4+t4+x (t5)
t5*t2 (rval)
Stack
%ebp
18
Understanding arith
int arith
(int x, int y, int z)
{
int t1 = x+y;
int t2 = z+t1;
int t3 = x+4;
int t4 = y * 48;
int t5 = t3 + t4;
int rval = t2 * t5;
return rval;
}
# eax = x
movl 8(%ebp),%eax
# edx = y
movl 12(%ebp),%edx
# ecx = x+y (t1)
leal (%edx,%eax),%ecx
# edx = 3*y
leal (%edx,%edx,2),%edx
# edx = 48*y (t4)
sall $4,%edx
# ecx = z+t1 (t2)
addl 16(%ebp),%ecx
# eax = 4+t4+x (t5)
leal 4(%edx,%eax),%eax
# eax = t5*t2 (rval)
imull %ecx,%eax
19
Another Example
int logical(int x, int y)
{
int t1 = x^y;
int t2 = t1 >> 17;
int mask = (1<<13) - 7;
int rval = t2 & mask;
return rval;
}
logical:
pushl %ebp
movl %esp,%ebp
movl
xorl
sarl
andl
movl %ebp,%esp
popl %ebp
ret
8(%ebp),%eax
12(%ebp),%eax
$17,%eax
$8185,%eax
8(%ebp),%eax
12(%ebp),%eax
$17,%eax
$8185,%eax
eax
eax
eax
eax
=
=
=
=
Set
Up
Body
Finish
x
x^y
(t1)
t1>>17 (t2)
t2 & 8185
20
ISA Properties
CISC - Complex Instruction Set Computer (e.g. x86)
Summary
Today
Arithmetic instructions
Next Time
22
Extra slides
Announced in Feb. 95
Features
24
Microprocessor Report
2/16/95
PentiumPro Operation
Translates instructions dynamically into Uops
Consequences