News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Divide by 2?

Started by paulfaz, November 27, 2006, 04:42:52 PM

Previous topic - Next topic

paulfaz

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

ToutEnMasm

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
















       

paulfaz

hi mate, thanks for that, that helps greatly.