Adblock breaks this site

What's wrong with my code?

Discussion in 'Programming General' started by -------owned-------, Jul 12, 2008.

  1. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    What's wrong with my code?

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    int main() {
    int i;
    int a = 1;
    asm( 
    "MOV i, a"
    );
    cout << "i";   
    system("PAUSE");
    }
    
    I tried to use "inline assembly", please note that I barely know ASM at all, I don't know if my ASM is correct. I'm using Dev-C++ (Uses GCC, aye?).

    Thanks,
    Adam.
     
  2. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    What's wrong with my code?

    asm(
    "MOV i, a"
    );

    Don't you have to concatenate the variable "a" instead of putting it in the string itself?

    cout << "i";

    That will output the actual letter, "i", if I'm not mistaken.

    http://en.wikipedia.org/wiki/Inline_assembler

    ^Some examples there.
     
  3. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    What's wrong with my code?

    Yeah, I realised that I had put "'s, lol.
    However, I get an error from the assembly: too many memory references for ´mov ´
     
  4. santa clause

    santa clause Guest

    Referrals:
    1
    What's wrong with my code?

    Ok, your code also lacks in cross-platform ability.

    Don't do system(...). Use a method such as getchar(), cin.ignore()/get() for ending a program. You system() arguments are platform dependent.

    As for your, ASM query. I am no pro at ASM but. You should.

    MOV 1 %eax
    MOV %eax 0

    Copy a's value into eax, then copy eax's value into i. This is not tested.
     
  5. 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
    What's wrong with my code?

    I have no clue with ASM, but I found a good tutorial for you:

    http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx

    Here is something along the lines of what you want:

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    int main()
    {
        int no = 100, val ;
            asm ("movl %1, %%ebx;"
                 "movl %%ebx, %0;"
                 : "=r" ( val )        /* output */
                 : "r" ( no )         /* input */
                 : "%ebx"         /* clobbered register */
             );
    
    
        std::cout << val;
    
        return 0;
    }
    
    (taken from the tutorial in the link posted above)
     
  6. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    What's wrong with my code?

    Thanks. :)
     
< Free File Hosting and Sub Domains | Help with my client plz... >


 
 
Adblock breaks this site