logo elektroda
logo elektroda
X
logo elektroda
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[Visual C++] Jak poprawnie wstawić kod asemblera w Visual C++?

pywoo 24 Sty 2004 13:26 5491 5
  • #1 488575
    pywoo
    Poziom 18  
    Posty: 390
    Pomógł: 10
    Ocena: 17
    jak w visual c++ powinna wyglądać wstawka z asamblera
    zrobiłem coś takiego na obsługe przycisku:
    void CSilnikprobDlg::OnStart() 
    {
    
    asm
     
            mov   dx,$378 
            mov   al,0
            out   dx,al 
    
    }
    

    ale podczas kompilacji zwraca 1 error
    robionc tą wstawke korzystałem z kursu vc++
    jak to powino wyglądac , gdzie jest błąd????

    [email]pywoo@wp.pl[/email]


    Temat zamykam. - arnoldziq
  • #3 489281
    pywoo
    Poziom 18  
    Posty: 390
    Pomógł: 10
    Ocena: 17
    niestety nie działa ale zonk jest w tym
    ze nawet nie pogrubia "asm" jako słowo kluczowe.
    i niestety w moim visual studio coś help nie trybi.
    kto pomorze???????
  • #4 490270
    h-doc
    Poziom 27  
    Posty: 1208
    Pomógł: 57
    Ocena: 21
    eh... minuta szukania w helpie:

    C++ Language Reference

    Writing Functions with Inline Assembly Using C or C++ in __asm Blocks
    Microsoft Specific

    If you write a function with inline assembly code, it's easy to pass arguments to the function and return a value from it. The following examples compare a function first written for a separate assembler and then rewritten for the inline assembler. The function, called power2, receives two parameters, multiplying the first parameter by 2 to the power of the second parameter. Written for a separate assembler, the function might look like this:

    ; POWER.ASM
    ; Compute the power of an integer
    ;
    PUBLIC _power2
    _TEXT SEGMENT WORD PUBLIC 'CODE'
    _power2 PROC

    push ebp ; Save EBP
    mov ebp, esp ; Move ESP into EBP so we can refer
    ; to arguments on the stack
    mov eax, [ebp+4] ; Get first argument
    mov ecx, [ebp+6] ; Get second argument
    shl eax, cl ; EAX = EAX * ( 2 ^ CL )
    pop ebp ; Restore EBP
    ret ; Return with sum in EAX

    _power2 ENDP
    _TEXT ENDS
    END
    Since it's written for a separate assembler, the function requires a separate source file and assembly and link steps. C and C++ function arguments are usually passed on the stack, so this version of the power2 function accesses its arguments by their positions on the stack. (Note that the MODEL directive, available in MASM and some other assemblers, also allows you to access stack arguments and local stack variables by name.)

    The POWER2.C program writes the power2 function with inline assembly code:

    /* POWER2.C */
    // Power2.c
    // compile with: /EHsc
    #include <stdio.h>

    int power2( int num, int power );

    void main( void )
    {
    printf( "3 times 2 to the power of 5 is %d\n", \
    power2( 3, 5) );
    }
    int power2( int num, int power )
    {
    __asm
    {
    mov eax, num ; Get first argument
    mov ecx, power ; Get second argument
    shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
    }
    /* Return with result in EAX */
    }
    The inline version of the power2 function refers to its arguments by name and appears in the same source file as the rest of the program. This version also requires fewer assembly instructions.

    Because the inline version of power2 doesn't execute a C return statement, it causes a harmless warning if you compile at warning level 2 or higher. The function does return a value, but the compiler cannot tell that in the absence of a return statement. You can use #pragma warning to disable the generation of this warning.

    END Microsoft Specific

    See Also
    Using C or C++ in __asm Blocks
  • #5 498302
    pywoo
    Poziom 18  
    Posty: 390
    Pomógł: 10
    Ocena: 17
    dzienki za pomoc ale ja chyba jestem na to za tępy
    chyba przeżuce sie na Delphi
  • #6 498888
    h-doc
    Poziom 27  
    Posty: 1208
    Pomógł: 57
    Ocena: 21
    Dlaczego za tępy? Różnica tkwi tylko w dyrektywie - zamiast asm daj __asm i po krzyku.
REKLAMA