Question

I'm having some difficulty with assembly syntax. In my assignment, we are required to pass a series of parameters to an x87 floating point register. One of those parameters is a double, and we're supposed to use this double as an array.

I've loaded it to the stack using fldl 4(%esp), but now I have the task of accessing its array elements. I know and understand the syntax to manipulate integer arrays in x86, but I don't understand how to access the indices of an array while it's on an x87 stack.

Because it's the only thing on my floating point stack, I know that it can be found at %st(0)

Was it helpful?

Solution

As per your comment, your function gets a double* argument. Thus 4(%esp) is a pointer to double, that is the base address where your array items are stored, at 8 bytes each. To access the i-th element, multiply i by 8 and add it to said base address. Assuming i is in eax you can load this element into the FPU like so:

movl 4(%esp), %edx   # load array base
fldl (%edx, %eax, 8) # load the array item whose index is in eax
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top