How to use asm code in c language. I am using turbo c++ complier
How to use asm code in c language. I am using turbo c++ complier
What have you tried?
Have you read the manual?
Have you searched the web?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Check out the asm keyword.
You must have TASM.EXE in the same directory as all your other BIN files.
Turbo C++ will see the asm keyword and will invoke TASM for you.
Ah,...inline assembly
Well, this is tricky because every compiler seems to do it a little differently.
As suggested, here is how you would do it in TurboC++
for a DOS program that only exits, returning exit code of 0Code:int main(int argc, char* argv[]){ asm mov ax,4C00h asm int 21h }
or even
for Microsoft's compilers, same thing but you use _asm instead of asm.Code:int main(int argc, char* argv[]){ asm{ mov ax,4C00h int 21h } }
for gcc, it is completely different, yet again, and you have to even use the AT&T style syntax instead of INTEL syntax. (personally, I hate the AT&T style, but, eh). The most annoying thing about AT&T style is that the operands are reversed, so you would have the thing to move on the left and where to move it on the right (instead of the way INTEL does it). I think newer gcc can use Intel syntax as well but haven't tried it.
anyhow, it is specific to compiler (and OS and processor, but you already knew that)
oh yeah, and you probably don't want to mess with ebp or bp in your inline assembly as most C compilers use it for tracking where you are in your program (stacks, procedure calls, and such).
Well not exactly...but I won't bother explaining. However this doesn't mean you can't use the stack and should be afraid of ebp or esp. If you are going to use the stack in your asm function and you are going to call this function from C...set this framework up every time and you will be ok.oh yeah, and you probably don't want to mess with ebp or bp in
your inline assembly as most C compilers use it for tracking where
you are in your program (stacks, procedure calls, and such).
push ebp ;save ebp
mov ebp,esp
...
...//asm code here
...
pop ebp ;restore ebp
ret
Last edited by VirtualAce; 05-06-2004 at 11:43 PM.
Well, what I meant was it uses ebp for pointing at the parameters passed to the function but also the return address is going to be on the stack somewhere. If you don't save the stack, when you return from function, you'll jump into the middle of some different bytecodes (probably not what you wanted) which hence will send you to a bad place in the program (aka, tracking where you are via the stack).Originally Posted by Bubba
But, yes, you are correct that you can be pretty safe by using the prolog and epilog code you gave there.
If I am mistaken here, please help me figure out where I went wrong??