Using the asm Keyword. McGraw-Hill The Complete Reference Fourth Edition
广告
广告
616
C + + : T h e C o m p l e t e R e f e r e n c e
{
MyClass ob1(7, 9), ob2(5, 2); cout << "Values in ob1 are " << ob1.getNumB() <<
" and " << ob1.getNumA() << endl; cout << "Values in ob2 are " << ob2.getNumB() <<
" and " << ob2.getNumA() << endl;
} return 0;
Here, nums is given an initial value when a MyClass object is created. Thus, no default constructor is required.
One last point: Class members are constructed and initialized in the order in which they are declared in a class, not in the order in which their initializers occur.
Using the asm Keyword
While C++ is a comprehensive and powerful programming language, there are a few highly specialized situations that it cannot handle. (For example, there is no C++ statement that disables interrupts.) To accommodate special situations, C++ provides a "trap door" that allows you to drop into assembly code at any time, bypassing the
C++ compiler entirely. This "trap door" is the asm statement. Using asm, you can embed assembly language directly into your C++ program. This assembly code is compiled without any modification, and it becomes part of your program's code at the point at which the asm statement occurs.
The general form of the asm keyword is shown here: asm ("op-code"); where op-code is the assembly language instruction that will be embedded in your program. However, several compilers also allow the following forms of asm: asm instruction ; asm instruction newline asm { instruction sequence
}
广告