I'm trying to print a number stored in EBX to a pointer in EDI and for some reason the second time the loop goes and divides eax by 10 the problem happens. So when I ran the code the first loop turns 8000 into CCC and the second turns CCC into CCCCCE14. I don't understand why this is happening.
The value of ebx is FFFF8000=-32768 when the procedure is called and edi points to value + 3.
value db 10,13,'         $'
ten dd 10 
mone dd -1
minus db '-$'
printnum proc near ;print ebx starting from position edi in string value
    mov ecx,0
    mov eax,ebx
    cmp eax,0    ;check if number is negative
    jg goagain
    mov ah,9
    mov dx,offset minus 
    int 21h
    mov eax,ebx
    imul mone       ;print a minus and convert number to positive
goagain:    
    inc ecx      ;counter
    div ten
    push edx
    cmp eax,0
    jne goagain
    dec ecx
poprint:
    pop ebx
    add ebx,'0'
    mov [edi+ecx],edx
    dec ecx
    cmp ecx,0
    jge poprint
    ret
printnum endp