I'm new to ASM (Just started 10 min ago - inline, to be exact), and am having what sounds to me like a syntax error. What confuses me is that the same line of code in a different ASM block works fine!
When attempting to compile the following code...
...I get the following error: "improper operand type" at the last line of assembly code (mov result, eax). What I don't understand at all is how I can have the same line in some previous inline ASM (which, btw, should return the same value), and have it work fine! That (working) code is as follows:Code:unsigned int x = 100; unsigned int result; //Intention: x = (x * (x + 1)) / 2 _asm { mov eax, x //eax = x mov ecx, eax //ecx = eax inc ecx //ecx += 1 mul ecx //eax *= ecx div 2 //eax /= ecx mov result, eax //result = eax } cout << result << "\n";
What is the difference between the two lines of ASM in the two different blocks? And why will the first one not work?Code:unsigned int x = 100; unsigned int result; _asm { xor eax, eax //eax will store the cumulative sum mov ecx, x //enter x into the loop counter label: add eax, ecx //add the counter value to the cumulative sum loop label //repeat mov result, eax //set result value }



LinkBack URL
About LinkBacks


