وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

Integer Math Instructions


Integer Math Instructions   ..




Add


Adds Source to Destination:


mov eax 100

add  eax  eax ; eax = 200


(Flags set on if overflow)




Sub


Subtracts Source from Destination:


mov eax 100

sub  eax  10 ; eax = 90


(Flags set on if overflow)




Inc


mov eax 12

inc eax ; eax = 13




Dec


mov eax 12

dec eax ; eax = 11




Mul


Multiplies eax by the given 32 Bits operand and stores the result in edx:eax

(Multiplies ax by the given 16 Bits operand and stores the result in dx:ax)

(Multiplies al by the given 8 Bits operand and stores the result in ax)


mov eax 24

  mov ecx 10

mul  ecx ; edx = 0  /  eax = 240




iMul


This instruction has 3 forms. The first one is just like upper mul:


Multiplies eax by the given 32 Bits operand and stores the result in edx:eax

(Multiplies ax by the given 16 Bits operand and stores the result in dx:ax)

(Multiplies al by the given 8 Bits operand and stores the result in ax)


mov eax  24

  mov ecx  0-10

imul  ecx ; edx = 0  /  eax = -240


Form 2 is, for example:


mov eax  24

mov ecx   0-10

imul  ecx  eax ; ecx = -240

imul  ecx  2 ; ecx = -480


Form 3 is, for example:


mov eax  24

mov ecx   0-10

imul  edx ecx  eax ; edx = -240

imul  edi  edx 2 ; edi = -480




Div


Divides a number in edx:eax by the given 32 bits argument. Result in eax

(Divides a number in dx:ax by the given 16 bits argument. Result in ax)

(Divides a number in ax by the given 32 bits argument. Result in al)


mov edx  0 ; zeroed edx (high dWord of 64 Bits)

mov eax  101 ; Value to be divided

mov ecx  10 ; Divisor

div ecx ; eax = 10  /  edx = 1


Quotient in eax (/ ax / al);  Remainder in edx (/ dx / ah).


Lets write a real life Macro example to adapt a size to user screen size (our development computer screen size is 800/600 and we want the user to see about the same things as we do):


[AdjustSizeToUserScreen  |  mov edx  0

mov  eax   #1  |  mul  D§UserScreenDim.X

mov  ecx  800 |  div  ecx  |  mov  #1  eax  |  #+1]

; ...

; ...


AdjustToScreenSize  D§MyBoxWidth  D§MyBoxHight





iDiv


Divides a number in eax by the given 32 bits argument. Result in eax

(Divides a number in ax by the given 16 bits argument. Result in ax)

(Divides a number in al by the given 8 bits argument. Result in al)


Quotient in eax (/ ax / al);  Remainder in edx (/ dx / ah).


mov eax  0-26

cdq ; see next paragraph (edx holds the sign)

mov ecx 10

idiv  ecx ; eax = 2  /  edx = 6




cdq / cwd / cbw


For iDiv instruction, we need to extend the declared sign of our value to edx / dx, because the division applies on these Registers pairs. cdq / cwd (Convert dWord to qWord / Convert Word to dWord) perform this required operation. cbw (Convert Byte to Word) does the same for ah Register for 8 bits divisions.

~~~~~~~