Assembly Question

Joined
Mar 9, 2004
Messages
3,322
Hello, I'm writing a compiler using flex/bison and am storing all variables in my symbol table as offsets from either ebp or the data segment if their globals. My target platform is linux protected mode x86 using intel syntax with the gnu assembler, but the code works fine with masm given a different header. (I really hate at&t syntax)

My problem is that I dont know how to find where the data segment begins in protected mode. I assumed that the data segment register held the offset to the begining of the data segment, but I dont think that is the case in protected mode.
http://www.lshift.net/blog/2010/03/31/what-has-happened-to-the-segment-registers

There has to be an easy way to find this offset right? I'd like to have the offset at compile time if possible. Any ideas?
 
The DS register is going to contain a segment descriptor, which is an index into the segment descriptor table The entry in the SDT gives the physical (or flat) offset of the segment, its length, and its protections.

The Intel programmers' guide gives you all the grit on this. I'd not expect your compiler to need to set this up, though; you're just getting your code called by an etry point the loader gives you, right?
 
Yeap, I didnt want to emit assembler specific code for each variable, so I just ended up allocated a named block of x bytes at the begining of .data and using that as a base address. Although now I'm tempted to read more into what you've mentioned.
 
Yeah, so you shouldn't be switching DS register values for the run of your application, had that been your plan. Unless you're emitting kernel-mode code, which would mean you have lots of other issues to worry about.
 
Back
Top