8086 Assembly - DIV going ape, IP jumping to a weird location endlessly

谁说我不能喝 提交于 2019-12-12 20:00:57

问题


i've been stuck with this problem for like a day, not finding any relevant information..

there's this one part in my code that takes a number (ex. 259) and separates it's digits into array slots.

SEPERATE_DIGITS:
    mov ax,RESULT               ; result is the number im working on. RESULT dw 259h
    mov si,0
    SEPERATE_DIGITS_LOOP:
        div TEN                 ; TEN dw 10h
        add dl,30h              ; fix-up to print later on
        mov SEPERATED[si],dl    ; store separated digit in my array.
        inc si
        cmp ax,0
    jne SEPERATE_DIGITS_LOOP

i have been debugging it on turbo debugger.. first division works fine. (25 goes to ax, 9 goes to dx).. next division, IP goes ape and just jumps to command "db FE" and again and again in an endless loop.

what the hell am i doing wrong? q:


回答1:


Here DIV's dividend is a 32-bit values taken from DX (top 16 bits) and AX (low 16 bits).
You need to zero out DX before every DIV to avoid reusing remainders as part of the dividend.

Also, start using a debugger. It helps.



来源:https://stackoverflow.com/questions/8236636/8086-assembly-div-going-ape-ip-jumping-to-a-weird-location-endlessly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!