0

So I'm trying to finish up my averaging program with float numbers, but I'm getting an invalid operand size. I don't understand what I'm doing wrong.

.386    
.model flat 
public _Average     
.code   

_Average proc
 finit
 mov ecx, [esp + 4]      
 mov ebx, [esp + 8]     
 fldz
 jecxz   Done

Do:
 fadd    REAL8 PTR [ebx]
 add     ebx, 8
 loop    Do
 fidiv   REAL8 PTR [esp + 4]

Done:
ret
_Average endp

.data   
 end
nrz
  • 10,435
  • 4
  • 39
  • 71
user2980447
  • 11
  • 1
  • 1
  • 3
    Why not tell us what line the error is on? This is not a "stump the panel" web site. Also, have you considered the possibility that the operand size is invalid? – Raymond Chen Nov 11 '13 at 19:38

1 Answers1

2

FIDIV divides ST(0) by an integer that can be either 16 or 32 bits, but you're trying to pass it a 64-bit operand:

fidiv   REAL8 PTR [esp + 4]

Use either

fidiv   WORD PTR [esp + 4]

or

fidiv   DWORD PTR [esp + 4]

and make sure that the value at [esp + 4] is an integer.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • A similar problem probably exists on the first operation. Is ebx really pointing to a float variable? – PMF Nov 11 '13 at 20:15