NASM x86 indexed float array 16-bit
I am trying to fill an array of double precision (64-bit) real numbers using loop instructions in 16-bit NASM x86, but I am getting an error invalid effective address
. OS is 32 bit Windows XP, but the program actually runs like 16 bit MS-DOS.
For example:
mov cx, 10
fill_array:
fld qword[yArray + cx*8]
fstp qword[xArray + cx*8]
loop fill_array
Returns the previous error on lines fld
and fstp
.
Arrays are declared like this:
yArray resq 10
xArray resq 10
I have also tried using register as a pointer to an array, but for example fstp qword[ax]
also fails.
Is there a way to use indexed float arrays in a 16 bit assembly? Do I need to use any specific FPU instructions?
source to share
On CPU> = 386, you can use scaling even in 16-bit mode, but only with 32-bit registers:
mov ecx, 10
fill_array:
fld qword[yArray + ecx*8]
fstp qword[xArray + ecx*8]
loop fill_array
But you have a "one by one" error. If ECX = 10 you are addressing the eleventh element of the list, and ECX = 0 will end the loop, that is, it will not be processed. You can avoid this with "hand-made":
mov ecx, 9
fill_array:
fld qword[yArray + ecx*8]
fstp qword[xArray + ecx*8]
sub cx, 1
jnc fill_array
The "pure 8086" solution:
mov cx, 10
mov bx, 0
fill_array:
fld qword[yArray + bx]
fstp qword[xArray + bx]
add bx, 8
loop fill_array
source to share