-
Junior Member
query
what's the use of asm keyword in c++?
-
Junior Member
Re: query
Hello,
Here is the answer to your query as follows:
The __asm keyword replaces C++ asm syntax. asm is reserved for compatibility with other C++ implementations, but not implemented. Use__asm.
The __asm keyword invokes the inline assembler and can appear wherever a C or C++ statement is legal. It cannot appear by itself. It must be followed by an assembly instruction, a group of instructions enclosed in braces, or, at the very least, an empty pair of braces. The term "__asm block" here refers to any instruction or group of instructions, whether or not in braces.
If used without braces, the __asm keyword means that the rest of the line is an assembly-language statement. If used with braces, it means that each line between the braces is an assembly-language statement. For compatibility with previous versions, _asm is a synonym for __asm.
Since the __asm keyword is a statement separator, you can put assembly instructions on the same line.
Example :
__asm {
mov al, 2
mov dx, 0xD007
out dx, al
}
Unlike braces in C and C++, the braces enclosing an __asm block don't affect variable scope. You can also nest __asm blocks; nesting does not affect variable scope.
Note : We use the inline assembler to embed assembly-language instructions directly in your C and C++ source programs without extra assembly and link steps. The inline assembler is built into the compiler, so you don't need a separate assembler such as the Microsoft Macro Assembler
-
Expert Member
Re: query
asm keyword is used for the declaration of an inline assembly block.
Example
asm("movl %ebx, %eax"); /* moves the contents of ebx register to eax */
__asm__("movb %ch, (%ebx)"); /* moves the byte from ch to the memory pointed by ebx */
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules