The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: paulfaz on November 27, 2006, 04:42:52 PM

Title: Divide by 2?
Post by: paulfaz on November 27, 2006, 04:42:52 PM
Hi All,

Can anyone explain to me howto divide by 2??, im having serious frustration getting it to work.

My goal is to divide an Allocation Granularity thats used for ViewMapOfFile.  Initially, dwAllocAlign is 64k, the Mapfile doesnt appear to work if the remaining MAP is less than 64k, when i detect a 0 pointer return, i want to divide dwAllocAlign by 2 and then repeat the process until dwAllocAlign is 0.

The DIV instruction is just confusing me, and i cant find a good example of it?

Thanks

Paul
Title: Re: Divide by 2?
Post by: ToutEnMasm on November 27, 2006, 05:03:08 PM
Hello,
shr eax,1      ;divide by 2 without remainder
shr eax,2       ;//          4  //                   2*2*....   

DIV             use edx and eax as  operand
                   use source (register) as divider
                result is in eax  with remainder in edx

sample:
mov edx,0
mov eax,13
mov ecx,2
div ecx
----------------------------------
remainder in edx,1
eax = 6
---------------------------------
2*6+1=13
















       
Title: Re: Divide by 2?
Post by: paulfaz on November 27, 2006, 05:25:34 PM
hi mate, thanks for that, that helps greatly.