Question

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
}

}

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top