Q58802: _asm Needed for Each Line of Inline Assembly Macros
Article: Q58802
Product(s): See article
Version(s): 2.00
Operating System(s): MS-DOS
Keyword(s): ENDUSER | S_QUICKASM | mspl13_c
Last Modified: 21-FEB-1990
In QuickC Version 2.00, the _asm keyword is needed between each code
line of inline assembly macros. _asm works as a statement separator
similar to the C comma or semicolon operators.
When writing #define macros in C, they must be written on a single
logical line. The escape character allows you to extend this logical
line over more than one source line in your program. However, it is
important to remember that the preprocessor is simply going to
concatenate the macro into one logical line before compilation.
Since assembly code is usually separated only by a new line, this
causes a problem with multi-line assembly macros. Putting the _asm
keyword before each assembly command forces the needed separation and
allows the macro to behave properly. This is described briefly in "C
For Yourself" on Page 277.
Sample Code
-----------
The following macro causes errors C4405 and C2400 when compiled under
QuickC:
#define SETPAGE( page ) _asm \
{ \
mov ah, 5 \
mov al, byte ptr page \
int 10h \
}
In the preprocessor, this concatenates to the following:
_asm { mov ah, 5 mov al, byte ptr page int 10h }
The correct syntax for the macro, as it appears on Page 277 of "C for
Yourself," is as follows:
#define SETPAGE( page ) _asm \
{ \
_asm mov ah, 5 \
_asm mov al, byte ptr page \
_asm int 10h \
}
Note that the first _asm statement before the opening curly brace ({)
is not needed.
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.