Results 1 to 3 of 3

Thread: query

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Answers
    11

    query

    what's the use of asm keyword in c++?


  2. #2
    Junior Member
    Join Date
    Feb 2008
    Answers
    3

    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


  3. #3
    Expert Member
    Join Date
    Mar 2012
    Answers
    208

    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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact