Teen Programmers Unite  
 

 

Return to forum top

Inline ASM in VC++

Posted by CodeRed [send private reply] at May 25, 2002, 01:46:12 PM

How do you do it? I was just trying to use some old code I had using inline assembly that I had writted for Borland. In Borland all you have to do is write asm before the line of code, or block it like asm{whatever}. VC++ apparently doesn't do it like that.

Posted by taubz [send private reply] at May 25, 2002, 03:08:42 PM

_asm or __asm I think

Posted by CViper [send private reply] at May 26, 2002, 04:18:56 AM

both should work (eg both _asm and __asm)

Posted by CodeRed [send private reply] at May 26, 2002, 12:47:39 PM

Yeah it does, thanks. It doesn't like any of my code though, guess Ill just use Borland

Posted by unknown_lamer [send private reply] at May 27, 2002, 12:56:49 PM

/me fetches his C reference manual:

asm ("instruction");

That would be one instruction. GCC has an extended form:

asm ("instruction0" : "instruction1" : "instruction2" : ... : "instruction n");

My reference manual also says some compilers support:

asm
{
more_than_one_instruction_here
}

Posted by Psion [send private reply] at May 27, 2002, 03:55:41 PM

Who wants to join me in pointing and laughing at unknown_lamer for doing something as ridiculous as telling how to do something in GCC in a thread with VC++ in its topic, and a thread that had already been resolved, at that?

Posted by CViper [send private reply] at May 27, 2002, 03:58:07 PM

"instruction" as a string? runtime compiling? nice :)
In vc++ you have to use __asm or _asm (with or without the block)..

Hmm.. anyone else using vc++ experiencing some fancy hangups when using inline assembly? Sometimes (seeming random) the whole IDE just stops responding to anything if i got .cpp /.inl file with assembly on the screen :/ (funny enough it dosent happen if it's offscreen)

Posted by buzgub [send private reply] at May 27, 2002, 10:31:13 PM

I'm joining Psion here...

/me points and laughs

Posted by CodeRed [send private reply] at May 27, 2002, 10:47:38 PM

It seems like he didn't read my whole post, but thanks for helping anyway lamer

Posted by unknown_lamer [send private reply] at May 29, 2002, 08:13:02 AM

No, asm is the standard C way. The C89 standard says that is how you do it: asm ("instruction"); the instruction is assembled with the assembler. It is in a string because it is passed to the assembler and the assembly instructions are (obviously) not going to conform to C grammar. I put the GCC way as well because I thought that maybe other compilers like VC++ did it that way too (no use in not trying). If VC++ doesn't support the asm ("...") call then that just shows how much more it sucks.

Posted by CodeRed [send private reply] at May 29, 2002, 08:27:41 AM

The point is Taubz had already answered my question, you use _asm. And VC++ doesn't suck, it's a hella lot better than GCC

Posted by unknown_lamer [send private reply] at May 29, 2002, 08:31:59 AM

In terms of standards support GCC 3.1 is much better than VC++. If you use _asm you have just made your code non-portable (I know..using asm in general makes your code non-portable, but you can at least try to make it portable to other operating systems on the same processor). All compilers should support the standard way of doing things, not their own stupid hacks. (quick correction: C89 does not have asm, C99 and the C++ standard do, therefore VC++ should still support it because it is a C++ compiler...).

Posted by CodeRed [send private reply] at May 29, 2002, 08:40:11 AM

Thats nice...

Posted by RedX [send private reply] at May 29, 2002, 02:47:07 PM

<WARNING: the following text contains high levels of sarcasm, read with caution. Keep away from children and idiots>

Visual C++ is M$-stuff. What did you expect? The whole idea is that you'll use it until you're death or retired (whatever comes first). This difference is a feature for your protection, in case you accidentally install an inferior compiler.
Why would anyone want to change to another compiler anyway? As if anyone can write a better one than the programmer of Microsoft.

RedX

Posted by CodeRed [send private reply] at May 29, 2002, 04:00:29 PM

It works perfectly fine for me and has been used to produce virtually ALL modern retail software products.

Posted by unknown_lamer [send private reply] at May 29, 2002, 08:57:20 PM

Just because everyone uses it doesn't make it good...

Posted by AngelOD [send private reply] at May 30, 2002, 05:07:32 AM

I'm afraid I'll have to agree with unknown_lamer on *that* bit.. The most popular thing isn't always the best.

But that's as far as I'll go, cuz I firmly believe that you choose what you want to use for your programming, then go with that. If you're using VC++, and you don't plan on programming for another system than Windows, then why should you switch compiler? Surely the best one for Windows-programming *is* VC++, given both products are MS?

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.