Inline ASM example

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

Inline ASM example
  1. Unread #1 - Feb 7, 2008 at 10:28 PM
  2. Govind
    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

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    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.
     
  3. Unread #2 - Feb 7, 2008 at 10:35 PM
  4. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    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.
     
  5. Unread #3 - Feb 8, 2008 at 2:29 AM
  6. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    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 :'(
     
  7. Unread #4 - Feb 8, 2008 at 5:12 PM
  8. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site