News:

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

divide overflow

Started by Liys, June 02, 2006, 05:03:52 AM

Previous topic - Next topic

Liys

Hi all:

  The following code is a functional assembly version of 'itoa', the question I have was that the placement of "mov dx, 0": To avoid "divide overflow" happens, the dx was set to zero, when it was place at #1 everything work well, but place it at #2 will cause "divide overflow". However, I don't see the difference between these two placements, cause either of them will set dx to zero before 'div'.

assume cs:code,ds:data

data segment
        dw 12, 23, 34, 45, 56, 12666
data ends
display segment
      db '000000000000000', 0
display ends

code segment

start:

      mov ax, data
      mov es, ax
      mov ax, display
      mov ds, ax
      call dtoc
      
      mov si, 0
      mov dh, 8
      mov dl, 3
      mov cl, 2
        call show_str

        mov ax,4c00h
        int 21h
dtoc:
       mov di, 0
            mov cx, 6
   s:   
       mov ax, es:[di]
       mov bx, 0AH
   s0:  mov dx, 0 ; #1
      div bx
      add dl, 30h
        mov byte ptr ds:[si], dl
      cmp ax, 0
      jz ok
        inc si
                        ; #2
        jmp short s0
      
     ok:inc si
      add di, 2
        loop s
     ret

sluggy

If you mov the mov dx, 0 from position #1 then it is possible that it will overflow when you initially hit that loop.