Inline Assembly Code (Cont.)
Features
Here is what you can do when writing inline assembly code:
- Use any instruction from the Intel instruction set.
- Use register names as operands.
- Reference function parameters by name.
- Reference code labels and variables declared outside the asm block.
- Use numeric literals that incorporate either assembler-style or C-style radix notation such as
0A2Ch
and 0xA2C
.
- Use the
PTR
operator in statements such as inc BYTE PTR[esi]
.
- Use the
EVEN
and ALIGN
directives.
Limitations
You can not do the following when writing inline assembly code:
- Use data definition directive such as
DB
(BYTE
) and DW
(WORD
).
- Use assembler operators (other than
PTR
).
- Use
STRUCT
, RECORD
, WIDTH
, and MASK
.
- Use macro directive, including
MACRO
, REPT
, IRC
, IRP
, and ENDM
, or macro operators (<>, !, &, %, and .TYPE
).
- Reference segments by name.
Length, Type, and Size
You can use the LENGTH
, SIZE
, and TYPE
operators with the inline assembler.
The LENGTH
operator returns the number of elements in an array.
The TYPE
operator returns one of the following, depending on its target:
- The number of bytes used by a C/C++ type or scalar variable
- The number of bytes used by a structure
- For an array, the size of a single array element
The SIZE
operator returns LENGTH×TYPE
.
Microsoft Visual C++ inline assembler does not support the SIZEOF
and LENGTHOF
operators.