dim as single num1(0 to kmax-1,0 to jmax-1,0 to imax-1)
by
REdim as single num1(0 to kmax-1,0 to jmax-1,0 to imax-1)
the result is fail ( it display : 13.3 + 14.4 = 14.4 )
What is wrong in the asm code with the REDIM declaration ?
Code: Select all
screenres 800,600,32
const imax = 30
const jmax = 20
const kmax = 10
dim as single num1(0 to kmax-1,0 to jmax-1,0 to imax-1) ' If I use DIM, the result is correct : 13.3 + 14.4 = 27.7
'redim as single num1(0 to kmax-1,0 to jmax-1,0 to imax-1) ' If I use REDIM, the result is wrong : 13.3 + 14.4 = 14.4
dim as single num2,num3
dim as integer k,j,i
k=8
j=5
i=3
num1(k,j,i)=13.3
num2=14.4
asm
mov ebx,dword ptr[k] ' ebx = k
imul ebx,jmax ' ebx = k*jmax
add ebx,dword ptr[j] ' ebx = k*jmax+j
imul ebx,imax ' ebx = (k*jmax+j)*imax
add ebx,dword ptr[i] ' ebx = (k*jmax+j)*imax+i
sal ebx,2 ' ebx = ((k*jmax+j)*imax+i)*4 = offset address
lea esi,[num1] ' esi = base address of num1(0,0,0)
add esi,ebx ' esi = base address + offset address = address of num1(k,j,i)
movss xmm0,dword ptr[esi] ' xmm0 = num1(k,j,i)
movss xmm1,dword ptr[num2] ' xmm1 = num2
addss xmm0,xmm1 ' xmm0 = num1(k,j,i) + num2
movss dword ptr[num3],xmm0 ' num3 = num1(k,j,i) + num2
end asm
?
? num1(k,j,i);" +";num2;" =";num3
sleep