views:

162

answers:

1

im confused about this i dont think that there should be any difference in both cases , the programm ends up as exe file please help if you think a differ....

ok let me clear my question . is there is a differece in the data segment defenition or handeling
between when i create an assembly program 'stand alone' and when i call for an assembly rutine from a c programm

who is defining the location or size of the date segment in both cases? is this the compiler ? or the operating system ? and how the value of the data segment determend in both cases ?

A: 

Depend of operating system!

If we are looking for windows operating system under IA32 then API reserve virtual memory address space of some application and:

  • CS segment, point to the start of program or code memory.
  • DS segment, point to the start of variable or data memory.
  • SS segment, point to the start of stack memory and is the same as DS.
  • ES as extra segment normally is in use for string transfer instructions (lodsb, stosw, ...) and is the same as DS.
  • FS as another extra segment point on OS kernel data like Win32 Thread Information Block.
  • GS as another extra segment is 0 as beginning of allocated virtual memory address space of loaded application.

Exsample of accessing 'Win32 Thread Information Block' via FS segment:

function GetThreadId: integer;
//result := GetCurrentThreadId;
asm
  mov   eax, fs:[$18]      //eax := thread information block
  mov   eax, [eax + $24]   //eax := thread id
end; { GetThreadId }

Sheck also: x86 memory segmentation

GJ