Results 1 to 7 of 7

Thread: New to ASM

  1. #1

    Thread Starter
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175

    New to ASM

    Hi,

    i'm new to ASM code.

    Before i start learning ASM code, i need to know if its a good sollution for my new project.

    For while i'm working on a game engine, last week started building a script engine using c++ styled scripts.

    I know how to lex and parse the c++ scripts. For the execution i was thinking of calling asm code from my c++ project.

    For now the script engine only can register and manupilate variables (can be a standard data type of structure or class)
    It's not using ASM code yet.

    I have done some more reading about c++ compilers and noticed before making an exe of it, the make some kind of ASM code of it (opcode), as i understanded, using asm code the script engine is more powerfull.


    The big idee behind the script engine, is making an independe script engine (not linked to any existing game or game engine) where users can register functions they wanna use in theyre game scripts or implement headers in the game scripts so the application defined functions can be read from header.

    Greetz Nightmare

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Assembler is used more as optimization than to implement large sections of code.

    You may want to write the thing in C++ and then refactor piceces of it into assembler. Its safer, cleaner, and more reliable than going straight assembler.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3

    Thread Starter
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    You may want to write the thing in C++ and then refactor piceces of it into assembler. Its safer, cleaner, and more reliable than going straight assembler.
    i'm testing a little with asm now,
    for example, when i want the source

    Code:
    int nTest = 10 + 20;
    i can execute by doing

    Code:
    int Add( int nVal1, int nVal2 )
    {
    	return nVal1+nVal2;
    }
    or

    Code:
    int ASM_Add( int op1, int op2 )
    {
    	__asm
    	{
    		mov eax, op1
    		sub eax, op2
    		mov op1, eax
    	}
    	return op1;
    }

    i guess the ASM_Add has better performace than the normal Add function.

    now i'm looking if its possible to register variables from script right now.
    my variable are stored in a vector class, so i have to loop trough the vector to find the requested variable.

    for example

    int nTest = 0;

    this will first register a int variable on the vector.
    to set the value of the nTest is will need to look up the variable first.

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    mov eax, op1
    sub eax, op2
    mov op1, eax
    I don't think that's what you want. (did you mean substract?) Try this implementation. It's a little more underhanded than yours but I save a few instructions.

    Code:
     
    int add(op1, op2)
    {
    _asm
    {
    	mov eax, op1
    	add eax, op2
    }
    }
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  5. #5

    Thread Starter
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    I don't think that's what you want. (did you mean substract?) Try this implementation. It's a little more underhanded than yours but I save a few instructions.
    c&p wrong code, this was substract code in a add function

    had to be this
    Code:
    	_asm
    	{
    		mov eax, op1
    		add eax, op2
    		mov op1, eax
    	}
    	return op1;
    will add eax, op1 auto return the value of op1?

  6. #6
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    I know on MSVC++6 compilers, if you return an int value, whatever was in eax will be returned. Like I said, its underhanded but it saves instructions (esp. on something that small)
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  7. #7
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322
    Just so you know, your probably not going to see any speed difference between the asm version and the C++ version in that example.

    Just because you handcoded asm doesn't automatically mean that the code will be faster.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width