Does GCC assume that ss , ds and es point to the same seg ?
Posted: Mon Jul 21, 2008 1:21 am
Hi,
For example --------------------------------------------------------------------------------
//#include <stdio.h>
int gVar = 0;
void test(int * iPoint)
{
(*iPoint) = (*iPoint) + 1;
}
int main()
{
int sVar = 1;
test(&gVar); --> pass the data which is in the data segment
test(&sVar); --> pass the data which is in the stack segment
//printf("gVar = %d, sVar = %d\n", gVar, sVar);
return 0;
}
----------------------------------------------------------------------------------------------
Disassemble the test()
0000003D 55 push ebp
0000003E 89E5 mov ebp,esp
00000040 8B4508 mov eax,[ebp+0x8]
00000043 8B00 mov eax,[eax] --> ALWAYS use ds segment to get the value. This means if the data is in the stack segment and ss is different from ds. The data will NOT be processed properly.
00000045 8D5001 lea edx,[eax+0x1]
00000048 8B4508 mov eax,[ebp+0x8]
0000004B 8910 mov [eax],edx
0000004D 5D pop ebp
0000004E C3 ret
--------------------------------------------------------------------------------------------------
My question:
Does GCC always assume that ss and ds point to the same segment ?
If not, which GCC option can distinguished the above 2 situations ?
If so, does it mean that we must set the same value in ss and ds when we use C language?
Thanks a lot.
For example --------------------------------------------------------------------------------
//#include <stdio.h>
int gVar = 0;
void test(int * iPoint)
{
(*iPoint) = (*iPoint) + 1;
}
int main()
{
int sVar = 1;
test(&gVar); --> pass the data which is in the data segment
test(&sVar); --> pass the data which is in the stack segment
//printf("gVar = %d, sVar = %d\n", gVar, sVar);
return 0;
}
----------------------------------------------------------------------------------------------
Disassemble the test()
0000003D 55 push ebp
0000003E 89E5 mov ebp,esp
00000040 8B4508 mov eax,[ebp+0x8]
00000043 8B00 mov eax,[eax] --> ALWAYS use ds segment to get the value. This means if the data is in the stack segment and ss is different from ds. The data will NOT be processed properly.
00000045 8D5001 lea edx,[eax+0x1]
00000048 8B4508 mov eax,[ebp+0x8]
0000004B 8910 mov [eax],edx
0000004D 5D pop ebp
0000004E C3 ret
--------------------------------------------------------------------------------------------------
My question:
Does GCC always assume that ss and ds point to the same segment ?
If not, which GCC option can distinguished the above 2 situations ?
If so, does it mean that we must set the same value in ss and ds when we use C language?
Thanks a lot.