DJGPP - compiler error?

Programming, for all ages and all languages.
Post Reply
crackers

DJGPP - compiler error?

Post by crackers »

I've found something that I don't understand
This is C code

Code: Select all

void fun2(int *arg)
{
   *arg = 9;
}
and here is what i get after compiling with -S option

Code: Select all

.globl fun2
   fun2:
   pushl   %ebp
   movl   %esp, %ebp
   movl   8(%ebp), %eax
   movl   $9, (%eax)
   popl   %ebp
   ret
Problem is with lines

Code: Select all

movl   8(%ebp), %eax
movl   $9, (%eax)
First line is doing something like SS:[EBP + 8] -> EAX
and second one is doing 9 -> DS:[EAX]. Problems arise when argument of fun2 is on stack and DS != SS.

Code: Select all

int main()
{
 int arg;
 fun2(&arg);
}
Because movl $9, (%eax) will copy data to DS:[EAX] instead of SS:[EAX]
Is it just my imagination, lack of knowledge or is it bug in djgpp compiler?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:DJGPP - compiler error?

Post by Solar »

GCC - which DJGPP is based upon - supports "flat memory model" only. I.e., if you have DS != SS, you're screwed anyway. ;)
Every good solution is obvious once you've found it.
crackers

Re:DJGPP - compiler error?

Post by crackers »

Acha, thx for info
JAAman

Re:DJGPP - compiler error?

Post by JAAman »

more acurately, DS.base must equal SS.base -- they dont have to be the same selector, or the same limit

although most people do use a true flat mode, there are some who use a SS segment which is smaller, and contained within the flat DS segment where SS.base == DS.base, but SS.limit != DS.limit

however, most people simply use a true flat memory model where SS == DS
Post Reply