lea ecx,wtavg
push ecx
call StdOut
xor eax,eax
lea eax,wtsum ; I have values stored in these variables(integer data)
mov eax,[eax]
lea ecx,sumwts
mov ecx,[ecx]
div ebx ; The problem lies here, "Windows Stopped working"
lea edi,temp1
mov [edi],ebx
lea edi,rem
mov [edi],edx
print ustr$(eax),0,0
lea eax,pt
push eax
call StdOut
lea eax,rem
mov eax,[eax]
mov edx,100
mul edx
lea ebx,temp1
mov ebx,[ebx]
div ebx
xchg ebx,eax
print ustr$(ebx),13,10
lea eax, prompt
push eax
call StdOut
mov eax,100
push eax
lea eax,temp1
push eax
call StdIn
call ExitProcess
Asked
Active
Viewed 303 times
-1

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
-
Perhaps a bit more detail on what results you expect and what exact error you are seeing. – ouflak Dec 05 '14 at 08:50
-
Ensure: `0 <= edx < ebx` – Brett Hale Dec 05 '14 at 11:13
1 Answers
2
I don't see anywhere where you've actually set ebx
to something before attempting to divide by it.
It's unlikely to end well if ebx
is set to zero at that point since Documentation for the div
instruction indicates that an exception is raised for that situation:
if (Source == 0) Exception (DE); // divide error
If you're trying to divide something by sumwts
, you should probably load that into ebx
or use ecx
as part of the div
instruction:
lea ecx,sumwts
mov ebx,[ecx] ; Or leave as mov ecx,[ecx]
div ebx ; then use div ecx.
You may also want to ensure that edx
has been set to zero somewhere before the div
, since that's used in the division as well. For div ebx
, the actions are effectively:
tmp <- edx:eax
eax <- tmp / ebx, exception if eax would overflow
edx <- tmp % ebx

paxdiablo
- 854,327
- 234
- 1,573
- 1,953