What's wrong with my code?

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

What's wrong with my code?
  1. Unread #1 - Jul 12, 2008 at 9:58 AM
  2. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    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.
     
  3. Unread #2 - Jul 12, 2008 at 11:24 PM
  4. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    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.
     
  5. Unread #3 - Jul 13, 2008 at 4:35 AM
  6. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    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 ´
     
  7. Unread #4 - Jul 17, 2008 at 7:18 AM
  8. santa clause
    Referrals:
    1

    santa clause Guest

    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.
     
  9. Unread #5 - Jul 17, 2008 at 8:25 AM
  10. 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

    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)
     
  11. Unread #6 - Jul 21, 2008 at 10:02 AM
  12. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    What's wrong with my code?

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

Users viewing this thread
1 guest


 
 
Adblock breaks this site