Announcement

Collapse
No announcement yet.

ASM DIV ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Vladimir Shulakov
    replied
    Thank for an intelligible explanation !

    But I did not think - that EAX and EDX it is not to equate to =0= with an input in SUB, (for use INLINE ASM)
    And I think that the mistake of overflow should not result in an overload of the computer sometimes.

    I understand, that
    DIV - Divide

    Usage: DIV src
    Modifies flags: (AF,CF,OF,PF,SF,ZF undefined)
    Unsigned binary division of accumulator by source. If the source
    divisor is a byte value then AX is divided by "src" and the quotient
    is placed in AL and the remainder in AH. If source operand is a word
    value, then DX:AX is divided by "src" and the quotient is stored in AX
    and the remainder in DX.


    F6 /6 DIV r/m8 Unsigned divide AX by r/m8
    F7 /6 DIV r/m16 Unsigned divide DX:AX by r/m16; AX
    F7 /6 DIV r/m32 Unsigned divide EDX:EAX by r/m32 doubleword

    Thank
    V.Shulakov


    ------------------

    Leave a comment:


  • Florent Heyworth
    replied
    [OOPS - Bob answered while I was writing the following]

    Hi Vladimir

    This is not a bug - ! DIV works as follows (if my memory serves me right ):

    - if the source is a byte the dividend is assumed to be in AX, the quotient is returned in AL and the remainder in AH.

    - for words the dividend is assumed to be in the DX and AX register. The quotient is returned in AX and the remainder in DX.
    YOU HAVE TO CLEAR DX before dividing.

    - with 32 bits operand the divisor is assumed to be 64 bits long, the upper bits in EDX and the lower in EAX. The quotient is returned in EAX and the remainder in EDX. YOU HAVE TO CLEAR EDX before dividing.

    Here's an example:
    Code:
    #COMPILE EXE
    #REGISTER NONE
    FUNCTION PBMAIN AS LONG
             LOCAL lTmp AS LONG
             
             ! mov ax, 10
             ! mov dl, 2
             ! div dl
             ! mov lTmp, al
             MSGBOX STR$(lTmp)
             
             ! mov dx, 0    ; clear dx!
             ! mov ax, 3250
             ! mov cx, 2
             ! div cx
             ! mov lTmp, ax
             MSGBOX STR$(lTmp)
             
             ! mov edx, 0  ; clear edx!
             ! mov eax,3250
             ! mov ebx,2
             ! div ebx
             ! mov lTmp, eax
             MSGBOX STR$(lTmp)
             
    END FUNCTION
    [UPDATED]
    Of course if the number is a power of 2 (division by 2) you are better off using the faster and smaller:
    Code:
             ! mov eax, 3250
             ! shr eax, 1
             ! mov lTmp, eax
             MSGBOX STR$(lTmp)
    Cheers

    Florent


    [This message has been edited by Florent Heyworth (edited May 17, 2000).]

    Leave a comment:


  • Bob Zale
    replied
    The default DIV instruction is an unsigned divide which always assumes that the operand is in EDX:EAX. You want something like...

    mov eax, 3250
    mov edx, 0
    mov ebx, 2
    div ebx

    Bob Zale
    PowerBASIC Inc.


    ------------------

    Leave a comment:


  • Vladimir Shulakov
    started a topic ASM DIV ???

    ASM DIV ???

    Hi
    I have seen a problem, maybe bug...
    '---------------------------------------------------
    #COMPILE EXE
    FUNCTION PBMAIN AS LONG
    ! MOV EAX,3250
    ! MOV EBX,2
    ! DIV EBX ;<<<
    '
    ' = OR = !!!!!!!!!!!!!!!!
    '
    ' ! MOV EAX,3250
    ' ! MOV BX,2
    ' ! DIV BX ;<<<
    '
    ' = OR = !!!!!!!!!!!!!
    '
    ' ! MOV EAX,3250
    ' ! MOV Bl,2
    ' ! DIV Bl ;<<<

    'THIS ALL GIVES a ERROR of OVERFLOW !!!
    '____________________________________

    END FUNCTION
    '----------------------------------------------------

    ' EAX=00000CB2 CS=0177 EIP=004010A5 EFCGS=00010246
    ' EBX=00000002 SS=017f ESP=0063fd1c EBP=0063fd94
    ' ECX=00000000 DS=017f ESI=00000000 FS=435f
    ' EDX=00401068 ES=017f EDI=00000000 GS=0000
    ' BYTES - CS:EIP:
    ' f7 f3 8b 45 88 8d 65 f4 5f 5e 5b 5d c3 00 00 00

    WHAT IS IT ?
    OR USE CO-PROCESSOR INSTRUCTION FOR ASM DIVIDE ?!...?
    I test this on 3 computers .
    THANK FOR EXPLANATION .

    V.Shulakov

Working...
X