hi,
i wrote an assembly code in my c code but i don't know how to use c declared var in my assembly,if someone could help me :) thx

This functionality exists as a language extension so it depends on which compiler your using...So which compiler are you using?

Edited 5 Years Ago by gerard4143: n/a

hi,
i'm using code blocks and i didn't use _asm{} but i made a file .asm that i will link with my c code

Oh, then just declare an extern variable like so

extern int x;

and then include your asm code into the project. I never used code blocks so I don't know the specifics.

Edited 5 Years Ago by gerard4143: n/a

hi,
thanks for the help but it's not the right answer!!there is a stack problem!!
we need to access to the stack etc but i don't know how

hi,
thanks for the help but it's not the right answer!!there is a stack problem!!
we need to access to the stack etc but i don't know how

O.K. maybe you could tell us what the 'stack problem' is.

i mean when i declared an asm function in my c code with extern myfonction(var1,var2,var3) when i use these var in the assembly code i need to get them from the stack in the this order var3,var2,var1 but i need to use registers and know there positions in the stack,things i don't know

The easiest way around this problem is to create a function in C that's exactly the same as the asm function and then see how the C program calls that function...I would take an objdump of the C code and take it from there.

The next(and harder) approach is to handle the function call, in the C program, with inline asm, making sure you pass everything correctly.

here is my asm code: aux and itemset are two arrays declared in c that i didn't know how to use them in assembly

SEGMENT .code

GLOBAL _compar
_compar:
push ebp
mov ebp,esp
mov eax,dword [ss:esp+0*10]
cmp eax,dword [ss:esp+0*14]
jl fin
xor ebx, ebx
outer_loop:
xor esi,esi
inner_loop:
mov eax,[aux+esi]
cmp eax,[itemset+ebx]
jne isdifferent
add ebx, 2
cmp ebx,dword [ss:esp+0*10]
jne outer_loop
xor eax,eax
mov esp,ebp
pop ebp
ret
isdifferent:
add esi,2
cmp esi,dword [ss:esp+0*14]
jl inner_loop
fin:
mov eax,1
mov esp,ebp
pop ebp
ret
This article has been dead for over six months. Start a new discussion instead.