Hi everyone. I am writing a code that receives two numbers and puts them into strings. The first number works fine, but when the program tries to get the second number, it crashes. I found out that the problem is with "12(%ebp)."
If I change it to 8(%ebp) or 16(%ebp), the program works. Can anyone tell me why that is?
This is my main function:
#include <stdio.h>
#include <stdlib.h>
extern void getlarge(char *number1, char *number2, char *result);
int main(int argc, char *argv[])
{
unsigned char number1[256];
unsigned char number2[256];
unsigned char result[256];
getlarge(number1, number2, result);
printf("done\n");
system("PAUSE");
return 0;
}
Assembly function:
.section .data
numberone:
.ascii "Enter first number: \n"
.byte 00
numbertwo:
.ascii "Enter second number: \n"
.byte 00
formatstr:
.ascii "%s"
.byte 00
.text
.align 4
.global _getlarge
_getlarge:
pushl %ebp
movl %esp, %ebp
call _getnumberone
call _getnumbertwo
movl %ebp, %esp
popl %ebp
ret
.global _getnumberone
_getnumberone:
pushl %ebp
movl %esp, %ebp
pushl $numberone
call _printf
addl $4, %esp
movl 8(%ebp), %ebx
pushl %ebx
pushl $formatstr
call _scanf
addl $8, %esp
movl %ebp, %esp
popl %ebp
ret
.global _getnumbertwo
_getnumbertwo:
pushl %ebp
movl %esp, %ebp
pushl $numbertwo
call _printf
addl $4, %esp
movl 12(%ebp), %ecx //crashes with 12(%ebp) works with 8 or 16
pushl %ecx
pushl $formatstr
call _scanf
addl $8, %esp
movl %ebp, %esp
popl %ebp
ret
Thank you.