Hello, I would like to check a long a routine takes.
Is there a way to find that out ?

I tryed GetTickcount, but I had problems.

By hte way, how exactly does DIV works?:
MOV EAX, 1000 ; Value to divide
MOV EBX, 10 ;divident
DIV EBX ; divide!


Greets !
Posted on 2003-09-06 13:53:12 by Bubu-Boy
Hi, Bubu-Boy
For the speed benchmarking, try searching the board as there should be numerous examples on this.
As for the DIV thing, remember that the dividend always has twice as many bits as the divisor.


MOV EAX,1000
CDQ
MOV ECX,10
DIV ECX

The masm32 package comes with many help files, there you will find an opcode reference that might come in handy :)
Posted on 2003-09-06 13:56:58 by QvasiModo
Thank you QuasiModo :rolleyes:
Posted on 2003-09-06 16:05:41 by Bubu-Boy
Hi Bubu-Boy,

In the Agner.hlp file (\Masm32\help) you will find a sniplet to time your routines using RDSTC, it is not bad on a pentium but as the models of cpu rise it becomes less accurate as different caching schemes and a higher degree of parallelism (u/v pipe) begins to fudge the numbers. Any calls to an API in the code you want to check will completely foul your timings. Outside of those issues the routine is pretty good and easy to implement.
Posted on 2003-09-06 16:27:29 by donkey
from what the Intel tells me is that with div you place the value you want to divide in eax and the remainders goes into ebx... but it also says its a qword... which confused me...

since i kept getting errors i found out that i needed to clear ebx and eax to to be safe place the value i wanted to divide into eax place a value into ecx and did a div ecx then i added ebx to eax to get the final product..

xor eax,eax
xor ebx,ebx

mov eax,temp
mov ecx,02h
div ecx
add eax,ebx
mov AdjustedFileSize,eax

if i messed up on how this work pls explain but i think i did it right..
Posted on 2003-09-06 18:48:08 by devilsclaw
There is no need to clear eax, it is subsequently loaded with a value anyway but yes you have to clear ebx in most situations. There are apparently some that don't require it but I'm not sure which ones, I always clear it anyway.
Posted on 2003-09-06 19:02:03 by donkey

from pcasm-book.pdf ;)

div and idiv perform unsigned and signed divisions

The general format is:

div source

If the source is 8-bit then AX is divided by the operand, the quotiend is stored in AL and the remainder in AH.
If the source is 16-bit then DX:AX is divided by the operand, the quotient is stored in AX and the remainder into DX.
If the source is 32-bit then EDX:EAX is divided by the operand, the quotient is stored in EAX and the remaonder in EDX.

The idiv instructions works like the same way. There are no special idiv instructions like in the case of imul instruction.

If the quotient is too big to fit into its registers or the divisor is zero, the program is interrupted and terminates. A very common error is to forget to initialize DX or EDX before division.



Another thing, cant divide by a inmediate value.

A more technical reference (see Appendix B: x86 Instruction Reference):

B.4.59 DIV: Unsigned Integer Divide



DIV r/m8 ; F6 /6 [8086]

DIV r/m16 ; o16 F7 /6 [8086]

DIV r/m32 ; o32 F7 /6 [386]


DIV performs unsigned integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:

For DIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.
For DIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.
For DIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.


and like in the previous, is nearly the same for idiv...
B.4.117 IDIV: Signed Integer Divide


Nice day.
Posted on 2003-09-06 19:07:05 by rea
edx is not cleared; Clear it using xor edx, edx or cdq before the division.
Posted on 2003-09-06 22:13:10 by roticv
yes sorry your correct.. i got the two confused for a bit...
Posted on 2003-09-06 23:25:23 by devilsclaw
For 32-bit divisions

If you are doing an unsigned division with the div instruction, you must clear EDX with
xor edx,edx
but do NOT use cdq.

If you are doing a signed division with the idiv instruction, then you MUST precede it with the cdq instruction to insure that the sign will be extended to the EDX register. Do NOT use the xor edx,edx prior to a signed division.

None of the above must be done if the division immediately follows a mul or imul instruction.

Raymond
Posted on 2003-09-06 23:31:28 by Raymond