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

Inline ASM example

Govind

The One Musketeer
Joined
Apr 22, 2005
Sythe Gold
23
Messages
7,825
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.
 
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.
 
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.
Lol, COBOL on crack xD

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