Adblock breaks this site

Inline ASM example

Discussion in 'Programming General' started by Govind, Feb 7, 2008.

  1. Govind

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus
    Inline ASM example

    Made it C-compatible for Darby lawl.

    Code:
    #include <stdio.h>
    int main()
    {
        int x,y,z;
        __asm{
            MOV x,4 ;make x = 4
            MOV y,7 ;make y = 7
            MOV EAX,x ;put x in EAX
            MOV EBX,y ;put y in EBX
            ADD EAX,EBX ;should be self-explanatory...
            MOV z,EAX
        }
        printf("x + y = %i",z);
        return 0;
    }
    Output should be 11. Note that the syntax:
    Code:
    __asm{
    ; Assembler code
    }
    only works on Visual C++. On GCC/MinGW it's asm("<code>"); or something similar.
     
  2. Faskist

    Faskist Tuxhead
    Banned

    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0
    Inline ASM example

    You don't need the third variable, as far as I know.

    Code:
    printf("x + y = %d", x + y);
    Should work.

    EDIT: Also, fucking hell Assembly looks like COBOL on crack.
     
  3. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Inline ASM example

    Lol, COBOL on crack xD

    good work SMR. I need to see lots of C++ refreshers otherwise I will completely forget due to innactivity :'(
     
  4. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    Inline ASM example

    MOV result, z. Never use inefficient variable names, crook. EDIT L2USEREGISTERS
     
< Good place to learn java | Run command prompt windows from Visual Basic >


 
 
Adblock breaks this site