Indexed float array in NASM x86 16-bit

1k views Asked by At

I'm trying to fill an array of double-precision (64-bit) real numbers using the loop instructions in NASM x86 16-bit, but I get the invalid effective address error. The OS is Windows XP 32 bits, but the program actually runs as a MS-DOS 16-bit one.

For example:

    mov cx, 10
fill_array:
    fld qword[yArray + cx*8]
    fstp qword[xArray + cx*8]
    loop fill_array

Returns the previous error at the fld and fstp lines.

The arrays are declared this way:

yArray resq 10
xArray resq 10

I've also tried using a register as a pointer to the array, but, for example, fstp qword[ax] also fails.

Is there a way to use indexed float arrays in 16-bit assembly? Do I need to use any particular FPU instructions?

1

There are 1 answers

0
rkhb On BEST ANSWER

On CPUs >= 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 an "off-by-one error". If ECX=10 you address the eleventh element of the list and ECX=0 will end the loop i.e. it won't be processed. You can avoid that with a "hand-made" loop:

    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