View
19
Download
1
Category
Preview:
Citation preview
Nota: Se recomienda ver esta presentación teniendo a mano una copia de la convención de llamadas _CDECL, o en su defecto del apunte de cátedra.
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asm
GLOBAL sumarGLOBAL sumar
sumar:sumar:
pushpush ebpebp
movmov ebp, espebp, esp
movmov eax,[ebp+8]eax,[ebp+8]
addadd eax,[ebp+12]eax,[ebp+12]
movmov esp, ebpesp, ebp
poppop ebpebp
retret
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
Cómo compilar: nasm –f elf funciones.asm –o funciones.o gcc –c main.c –o main.o ld –oformat elf main.o funciones.o –o suma.
ab
c
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
c
b
a
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
1EIP (APROX)EIP (APROX)
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIP (APROX)EIP (APROX)
1
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIP (APROX)EIP (APROX)
Y=5
X=2
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIP (APROX)EIP (APROX) 2
Y=5
X=2
EIP del main
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}} ESP
EBP
Dirección de cre
cimien
to del Stack
EIPEIP Y=5
X=2
EIP del main
EBP del main
3
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}} ESPEBP
Dirección de cre
cimien
to del Stack
EIPEIP
Y=5
X=2
EIP del main
EBP del main
4
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}} ESPEBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
EIP del main
EBP del main
EBP + 8
5
EAX= 2
EAX= 2 + 5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}} ESPEBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
EIP del main
EBP del main
EBP + 12
Y=5
6
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}} ESPEBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
EIP del main
EBP del main
7
EAX= 7
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
EIP del main
8
EAX= 7 ---BASURA---
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x, y,z);printf("x = %d , y = %d, z = %d \n",x, y,z);
}}
ESP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
EIP del main
EBP
EAX= 7 ---BASURA---
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x, y,z);printf("x = %d , y = %d, z = %d \n",x, y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
9
EAX= 7 ---BASURA---
---BASURA---
Y=5
Ejemplo sencillo – sumar dos enteros.Ejemplo sencillo – sumar dos enteros.
funciones.asmfunciones.asmGLOBAL sumarGLOBAL sumarsumar:sumar:
pushpush ebpebpmovmov ebp, espebp, espmovmov eax,[ebp+8]eax,[ebp+8]addadd eax,[ebp+12]eax,[ebp+12]movmov esp, ebpesp, ebppoppop ebpebp
retret
Hacia direcciones inferiores de la memoria... 0x0000h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2Ch
Variables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x, y,z);printf("x = %d , y = %d, z = %d \n",x, y,z);
}}
ESP
EBP
Dirección de cre
cimien
to del Stack
EIPEIP
X=2
10
EAX= 7
Ahora continúa la ejecución de la función llamadora.
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
main.cmain.cextern intextern int sumar(int x, int y); sumar(int x, int y);void main (void)void main (void){{
int x=2, y=5, z;int x=2, y=5, z;z = z = sumar(x, y);sumar(x, y);printf("x = %d , y = %d, z = %d \n",x,y,z);printf("x = %d , y = %d, z = %d \n",x,y,z);
}}
1
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIPESPEBP2
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIPESPEBP
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
ESP
EBP
2
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
ESP
EBP
EBX val. original3
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
ESP
EBP
4
EBX val. original
EBX= 2
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
ESP
EBP
EBX val. original
EBX= 2
EBP + 8
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
ESP
EBP
EBX val. original
7
EBX= 2 + 5
EBP + 12
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
ESP
EBP
EBX val. original
7
EBX= 2 + 5
EBP - 4
5
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
ESP
EBP
6
EBX val. original
7
EBX= 7EAX= 7
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
ESP
EBP
EBX val. original
7
EBX= 7EAX= 7
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
EBP
7
7
ESP
EBX= XXXXEAX= 7
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5EIPEIP
EBP 7
ESP
EBX= XXXXEAX= 7
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
8
7ESP EBP
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
7EBPESP
Ejemplo sencillo – sumar dos enteros. Ahora utilizando Ejemplo sencillo – sumar dos enteros. Ahora utilizando variables locales al stackvariables locales al stack
funciones.asmfunciones.asm
global sumarglobal sumar
sumar:sumar:pushpush ebpebpmovmov ebp,espebp,espsubsub esp,4esp,4pushpush ebxebxmovmov ebx,[ebp+8]ebx,[ebp+8]addadd ebx,[ebp+12]ebx,[ebp+12]movmov [ebp-4],ebx[ebp-4],ebxmovmov eax,[ebp-4]eax,[ebp-4]poppop ebxebxmovmov esp,ebpesp,ebppoppop ebpebpretret
Hacia direcciones inferiores de la memoria... 0x0000h
0x14h
0X18h
0X1Ch
0X20h
0x24h
0x28h
0X2ChVariables locales al main
Hacia direcciones superiores de la memoria... 0xffffh
Dirección de cre
cimien
to del Stack
X=2
EIP del main
EBP del main
Y=5
EIPEIP
9
---BASURA---ESPEBP
10
Su pregunta no molesta!!!!!
Recommended