[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppAsm
Things inline Assembler CAN do: Things inline Assmbler CANNOT do: The code below makes your computer beep:
Below some examples are given for C/C++ statements and how to achieve the same using assembler mnemonics.
Jumps can only be performed to labels in the same assembler code block. When trying to jump from another function to the one above, an error will be given:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppAsm
(C++) asm
Keyword enabling you to use assembler code.Things inline Assembler CAN do: Things inline Assmbler CANNOT do: The code below makes your computer beep:
int main()
{
asm
{
mov ax, 0x0E07
xor bx,bx
int 0x10
}
return 0;
}
Below some examples are given for C/C++ statements and how to achieve the same using assembler mnemonics.
ADD
int main() { int x = 1; int y = 2; int z = 0; asm { mov eax,x add eax,y mov z,eax } assert(z==3); return 0; }
- include <cassert>
JMP
Performs an unconditional jump, similar to the keyword goto.int func1() { const int x = 1; const int y = 2; //z cannot be made const (which is a good thing) //doing so gives the error 'operand size mismatch' int z = 0; asm { jmp labelFunc1 //Jumps to labelFunc1 mov eax,x //Will be jumped over, stores the value of x in EAX jmp labelEnd //Will be jumped over, jumps to labelEnd labelFunc1: //Label mov eax,y //Store the value of y in EAX labelEnd: //Label mov z,eax //Store the value of EAX in z }; assert(z==y); return z; }
- include <cassert>
Jumps can only be performed to labels in the same assembler code block. When trying to jump from another function to the one above, an error will be given:
int func2()
{
int z;
asm
{
jmp labelFunc1; //ERROR! Undefined label 'labelFunc1'
mov z, eax;
labelFunc2:
}
return z;
}
MOV
int main() { char x = 1; assert(x==1); asm mov x,0 //Set the value of x to 0, equal to 'x = 0;' assert(x==0); return 0; }
- include <cassert>
'asm' links
- ?C
References
- 1) MSDN: http://msdn2.microsoft.com/en-us/library/fabdxz08.aspx
- ?) Not sure
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
