
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.
arg-highlightedPosts="Array"
args="" />

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.
arg-highlightedPosts="Array"
args="" />

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.
Yeah, I realised that I had put "'s, lol.
However, I get an error from the assembly: too many memory references for ´mov ´
arg-highlightedPosts="Array"
args="" />

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.
arg-highlightedPosts="Array"
args="" />

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)
arg-highlightedPosts="Array"
args="" />

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)
Thanks.

arg-highlightedPosts="Array"
args="" />