Hi,
I just have a question about mixing asm and C.
If I have an ASM function that takes three args say a WORD, BYTE and DWORD, C prototype like this
SomeFunc( WORD, BYTE, DWORD );
If I call it from C like this
SomeFunc( 32546, 200, 20059958 );
I know that C passes these args from right to left.
If I have a 32Bit stack would I access the args like this
push ebp
mov ebp, esp
mov eax, word [ebp + 4] ; the word arg
mov ebx, byte [ebp + 6] ; the byte arg
mov ecx, dword [ebp + 7] ; the dword arg
.....
pop ebp
ret
I guess what I am asking is that if a stack has 32Bit pushes/pops by default, will a WORD on the stack still only be 2 bytes or will it be padded to 4 bytes?
thanks.
C and Asm
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C and Asm
the stack has 32bits pushes only. thus pushing 3 bytes requires the same stack amount as pushing 3 ints. This is for memory alignment purposes (too slow to read the return address at a non-multiple of four address because it could be on a cache line barrier and issue 2 memory read cycles instead of 1)
-
PlayOS
Re:C and Asm
So then to get at my args I will have to do this:
push ebp
mov ebp, esp
mov eax, [ebp + 4] ; the word arg
mov ebx, [ebp + 8] ; the byte arg
mov ecx, [ebp + 12] ; the dword arg
; ax = word arg
; bl = byte arg
; ecx = dword arg
.....
pop ebp
ret
would this be correct?
push ebp
mov ebp, esp
mov eax, [ebp + 4] ; the word arg
mov ebx, [ebp + 8] ; the byte arg
mov ecx, [ebp + 12] ; the dword arg
; ax = word arg
; bl = byte arg
; ecx = dword arg
.....
pop ebp
ret
would this be correct?
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
-
willow
Re:C and Asm
I'm searching for that, what is the command for calling a fonction made in ASM from a C file ?!!! please help me
can we put the asm code in the c file or we link ik ???
i don't know help me
email me at : [email protected]
can we put the asm code in the c file or we link ik ???
i don't know help me
email me at : [email protected]
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C and Asm
basically,
1) write your ASM function in a separate .asm file and declare it to be global
2) declare your asm function in C code (and beware bad arguments)
3) just call your function as if it was a C function.
If you need more infos about how to pass arguments (trough the stack
) or how to receive a return value (through %eax), i suggest you study a disasembled version of some of your C functions.
1) write your ASM function in a separate .asm file and declare it to be global
Code: Select all
global nope
nope:
nop
ret
Code: Select all
void nope();
If you need more infos about how to pass arguments (trough the stack
-
Willow
Re:C and Asm
You are my hero!!! byt when i compile my file do a make the same thing ?? And if i take TASM is it the same thing
thanck
email me: [email protected]
thanck
email me: [email protected]
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C and Asm
oh, well, yes ...
the asm directive "global" might have another name in your assembler (just check your manual
...
Also, under MsDos environment, the compiler prepends a "_" before any C name, so the nope() C function call looks for the _nope assembler function...
the asm directive "global" might have another name in your assembler (just check your manual
Also, under MsDos environment, the compiler prepends a "_" before any C name, so the nope() C function call looks for the _nope assembler function...