• Log in or sign up for an account here: https://www.sythe.org/login

Inline ASM example

Govind

The One Musketeer

Highly Respected
Mudkips
Retired Administrator
Joined
Apr 22, 2005
Sythe Gold
23
Messages
7,825
Le Monkey
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
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.
 
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.
 
Member of the Month Winner
Sythe's 10th Anniversary
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.
Lol, COBOL on crack xD

good work SMR. I need to see lots of C++ refreshers otherwise I will completely forget due to innactivity :'(
 
MOV result, z. Never use inefficient variable names, crook. EDIT L2USEREGISTERS
 
Runescape Gamblingrunescape gambling
Back
Top