Visual C++ with Assembler
Hello,
Can someone give an example of using assembler with a win32 app in visual c++ 6.0?
Thanks
I know that there is some assembler MASM win32 application example at www.grc.com - site is worth checking out anyway - but I don''t think it deals with VC++ !?!
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
November 30, 2000 09:45 AM
it''s really easy.
just load the .asm files into your project,
and go to Project->settings->custom build step
and configure it.
that''s all
just load the .asm files into your project,
and go to Project->settings->custom build step
and configure it.
that''s all
The inline assembler should be able to take care of your assembly needs. Pretty much all MASM (Microsoft Assembler) commands, directives, etc. are valid within a block of inlined assembly. Using it is very simple.
Start the block like this:
__asm
Then you have the opening curly brace, your assembly code, then a closing curly brace. I'll give an example C/C++ function that uses the inline assembler to calculate an absolute value. (A slightly outdated version of this function is in the MSDN library, I updated it to work for long integers.)
long asmAbs(long abNum)
{
__asm
{
// you can use normal C++ comments
// or assembly-style comments
// that start with the semicolon like the following
; assembly style comment
mov ebx, abNum
cwd ; replicate the high bit into DX
xor eax, edx ; take 1's complement if negative
; no change if positive
sub eax, edx ; AX is 2's complement if it was negative or ebx, ebx ; see if number is negative
jge notneg ; if it is negative...
neg ebx ; ...make it positive
notneg: ; jump to here if positive
mov eax, ebx
}
// Note that there is no return value. You will probably
// receive a warning when you compile the program, but you can
// ignore it. A value is being returned by placing the result
// of the assembly operation into eax. The compiler doesn't
// know that however
}
Notice that you can reference your C++ variables in the assembly code.
Hope this helps!
Edited by - GHoST on November 30, 2000 11:25:15 AM
Start the block like this:
__asm
Then you have the opening curly brace, your assembly code, then a closing curly brace. I'll give an example C/C++ function that uses the inline assembler to calculate an absolute value. (A slightly outdated version of this function is in the MSDN library, I updated it to work for long integers.)
long asmAbs(long abNum)
{
__asm
{
// you can use normal C++ comments
// or assembly-style comments
// that start with the semicolon like the following
; assembly style comment
mov ebx, abNum
cwd ; replicate the high bit into DX
xor eax, edx ; take 1's complement if negative
; no change if positive
sub eax, edx ; AX is 2's complement if it was negative or ebx, ebx ; see if number is negative
jge notneg ; if it is negative...
neg ebx ; ...make it positive
notneg: ; jump to here if positive
mov eax, ebx
}
// Note that there is no return value. You will probably
// receive a warning when you compile the program, but you can
// ignore it. A value is being returned by placing the result
// of the assembly operation into eax. The compiler doesn't
// know that however
}
Notice that you can reference your C++ variables in the assembly code.
Hope this helps!
Edited by - GHoST on November 30, 2000 11:25:15 AM
"That's a very nice hat."-Korben Dallas
November 30, 2000 10:08 AM
listen kids, there is no such thing as an "assembler" language, it''s called an "assembly" language. to simplify things, the assembler just assembles the assembly code. get it? just so you know....later
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement