8086组装-DIV不断进化,IP无休止地跳到一个奇怪的地方 [英] 8086 Assembly - DIV going ape, IP jumping to a weird location endlessly

查看:72
本文介绍了8086组装-DIV不断进化,IP无休止地跳到一个奇怪的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题困扰了我整整一天,没有找到任何相关信息.

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

我的代码中有一部分需要一个数字(例如259)并将其数字分隔到数组插槽中.

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

我一直在Turbo调试器上调试它. 第一师工作正常. (25代表斧头,9代表dx). 下一个分区,IP变成了猿,只是一次又一次地跳转到命令"db FE",无休止地循环.

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:

推荐答案

这里DIV的红利是从DX(高16位)和AX(低16位)中提取的32位值.
您需要在每个DIV之前将DX归零,以避免重复使用剩余作为红利的一部分.

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.

这篇关于8086组装-DIV不断进化,IP无休止地跳到一个奇怪的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆