KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q40101: Using C within _asm Blocks of Assembly Code

Article: Q40101
Product(s): See article
Version(s): 2.00
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 24-JAN-1989

The following elements of C may be used in in-line assembly blocks of
code:

1. C variable names

2. C labels

3. C macros

4. C function identifiers

5. C comments

6. C named constants, including "enum" members

7. C typedef names, generally used with operators, such as PTR
   and TYPE, or to specify structure or union members

These elements of C must be used in accordance with the following
two conventions:

1.  Only one C symbol can be referenced for each assembly instruction,
    unless used in conjunction with the TYPE, LENGTH, or SIZE operators.

2.  Functions referenced within an _asm block must be prototyped
    previously in the program. Otherwise QuickC cannot distinguish
    functions from labels.

The following code illustrates the use of some the above C elements
within an _asm block:

void main(void) ;

void main ()
{
  int  result ;
  int   Count ;

  result = 0 ;
  Count = 16 ;

  /* result = count * count */

  _asm {
         mov  ax, Count
         imul ax,
         mov  result, ax
       }
}

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.