0

I have a task - calculate 6 results of function (Y = (20 * x) /(5 * x2 – 8,5)) the x - start from 1 and each calculation must increas by 4 (1, 5, 9 ..).

I write some code but i dont understand how to made loop and put data to array. All operation must be on asm - loop and put to array, 1 iteration - 1 element in array

There is my code:

int main()
{
float REZ[6];
int x = 1;
int A =5;
int B=20;
float C = 8.5;
int D =2000;
int increment = 4;
float part;
float val;

_asm{
finit   
fild x
fimul x
fimul A
fsub C
fstp part
fild D
fimul x
fdiv part
fstp val
}

}

Andrew
  • 266
  • 6
  • 18
  • If this is a question about assembly, remove the [tag:c++] since it is confusing. At least I don't know wether you ask for a loop in C/C++ or in assembly. Either way, look at [assembly info](http://stackoverflow.com/tags/assembly/info) or [c++ info](http://stackoverflow.com/tags/c%2b%2b/info) – Olaf Dietsche Nov 03 '12 at 16:18

1 Answers1

1

My assembly times are long gone, but I'll try. A loop in assembly is done by defining a label and jumping to this label. Depending on the loop, it is a conditional jump (after some comparison):

Pseudo assembly:

label1:
    ...
    cmp x, 6
    jlt label1

Look at X86 Assembly/Control Flow for details.

Or unconditional jump:

label1:
    ...
    jmp label1

Another way to learn about assembly is looking at compiler output. See for example:

int x, y;
for (x = 0; x < 6; ++x)
    y = (20 * x) / (5 * x2 – 8,5);

Tell gcc to stop at assembly output:

gcc -S loop.c

and look for the resulting loop.s

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • when i use x86 i do somthing like this: 'code'lea EBX, REZ mov ECX, 6 ;loop counter ... mov dword ptr[EBX], EAX ; put to array add EBX, 4 ;take next adress in array But it is not work in x87 – Andrew Nov 03 '12 at 16:55
  • x86 is about intel processors. x87 is about the floating point unit of x86. So this should work in your case too. The difference might be in accessing the floating point result, like `fld, fst` or similar. Try looking at assembly output from the compiler. – Olaf Dietsche Nov 03 '12 at 17:25
  • thnks a lot i do id, but suddenly it not purly x87, partly x86 – Andrew Nov 03 '12 at 17:48