Hello,
operating system : openSUSE 11.4 (32 bit)
file system: ELF
I have an single tset.so file which contains two object files. One of these object files was successfully generated
from c-sourcecode using gcc. The other object file was successfully generated from an assembler sourcecode,
which was generated using nasm (latest version). These two object files are linked together using
ld -shared -o test.so cobject.o asmobject.so.
Now, I have an c-structure defined and an instance of this structure inside the c-sourcecode.
So, an implemented c-function calls an function, which is placed inside the assemblercode,
As the argument, the assembler function takes the address of the c-structure, because
I have to access the members of the c-structure using this pointer.
I read the nasm documentation trying to find information for this example but I couldn't find
an detailed description.
No I will place the example code for better understanding:
//************************************************************************************************
// Start c - code
typedef struct t1
{
int int1;
int int2;
int int3;
struct
{
int s0[2];
int s1[10];
int s2;
} b[2];
int int4;
int int5;
int int6;
};
struct t1 my_struct;
extern int asm_function(struct t1* pt1);
void initialize_members_of_structure(struct t1* pt1);
void caller_function_c_code(void
{
int result = 0;
initialize_members_of_structure(&my_struct)
result = asm_function(&my_struct);
return;
}
void initialize_members_of_structure(struct t1* pt1)
{
// Initializes the members of the structure referenced by pt1
// The values of the members inside the structure are not of
// special interest for this example
// so we only have to return
return;
}
// End c - code
//************************************************************************************************
;*************************************************************************************************
; Start of assembler code
cpu 586
bits 32
global asm_function:function ; declare it as a function
extern _GLOBAL_OFFSET_TABLE_
section .bss
; some uninitialized data
bss_pointer_2_structure: resd1
section .data
; some initialized data
teststr: db "Hello world !"
db 10, 0
section .text
;*********************************
; store GOT to EBX
;*********************************
%macro get_GOT_EBX 0
call %%getgotebx
%%getgotebx:
pop ebx
add ebx, _GLOBAL_OFFSET_TABLE_+$$-%%getgotebx wrt ..gotpc
%endmacro
asm_function:
push ebp ; Save ebp
mov ebp, dword esp ; esp to ebp
add ebp, dword 8 ; ebp points to the one and only parameter
get_GOT_EBX ; store GOT to ebx
mov eax, dword [dword ebp] ; Adress of the the c - structure to eax
mov [dword ebx+bss_pointer_2_structure wrt ..gotoff], eax ; Store Adress of the the c - structure to bss_pointer_2_structure
;???????????????????????????????????????????????????????????????????????????????????????????????????????????????
; Now, how can I access the data members of th c - structure using the address stored in bss_pointer_2_structure
; I want to write a value in each member of the c - structure
; How do I have to do this ?
;???????????????????????????????????????????????????????????????????????????????????????????????????????????????
;********************************************************
; asm Code should be placed here
;********************************************************
;********************************************************
; function exit
xor eax, eax ; return code is zero
pop dword ebp
; the c - function should clear the stack frame
ret
; End of assembler code
;*************************************************************************************************
Thank you for help !