Mail Archives: djgpp/1997/04/26/07:37:56
Hello,
I'm new to DJGPP, and have some problems combining my assembly functions
with gcc. It seems to be impossible, to use local data in my assembly
modules. If I load a register with the value of a variable, I allways get
the value of the first variable. Example:
var1 dd 1
var2 dd 2
var3 dd 3
[...]
mov eax,var3
If I return to the calling c-function and print the value, it contents
a 3. I don't know why. If I load the eax-register with an absolute
value (like mov eax,3), the c-function prints the right value.
So I thought there goes something wrong with the data segments, but I
don't use any in my assembly function, and I thought gcc wouldn't use
any either (or am I wrong?).
Here is an example:
--------------------------------------------------------------------------
/* Assembly-Module, called testasm.asm */
.586p
.model flat,c
.code
align 4
var1 dd 1
var2 dd 2
getvar2 proc near public
mov eax,var2
ret
getvar2 EndP
END
--------------------------------------------------------------------------
/* C-Module, called test.c */
#include <stdio.h>
unsigned long getvar2 ();
main() {
printf ("The value is: %u\n",getvar2 () );
}
--------------------------------------------------------------------------
I have compiled the assembly module with MASM 6.11d: ml /c /coff testasm.asm
and the c-module with gcc 2.7.2.1: gcc -o test.exe -O testasm.obj test.c
If I start this program, it returns: "The value is: 1", but it must be "2".
I altered the function to "mov eax,cs:var2", but it still returns "1".
Can anyone explain me this? It would be great, if someone can help me to
fix this problem.
Thanks,
Patrick
--
Patrick Fedick <patrick AT pfp DOT de>
- Raw text -