【问题标题】:"Divide error -Overflow" error in 8086 emu8086 emu 中的“除法错误 - 溢出”错误
【发布时间】:2020-12-07 15:17:31
【问题描述】:

编写一个汇编语言程序来添加一个表格中所有在 50 到 100 之间的元素。将结果显示为十进制值。

我的解决方案:

.model small 
.stack 64
.data
    table db 0, 25, 50, 75, 100, 125, 150, 175, 200 
    ten db 10
.code
    main proc
        mov dx, @data
        mov ds, ax
        lea si, table
        mov dx, 0
        mov bx, 0
        mov cx, 9
    l2: mov ax, [si]   
        cmp ax,   50
        jb l1
        cmp ax, 150
        ja l1
        add ax, dx
        mov dx, ax
    l1: inc si
        loop l2
    l3: mov dx, 0
        div ten
        add dx, 30H
        push dx
        inc bx
        cmp ax, 0
        jne l3
        mov ah, 02H
    l4: pop dx
        int 21h
        dec bx
        jnz l4 
        mov ax, 4c00H
        int 21H
    main endp 
end main

显示错误-->> 除法错误-溢出。要手动处理此错误,请更改中断向量表中INT 0的地址。

对此有什么解决方案。 谢谢!

【问题讨论】:

  • 您的表格是字节,但您加载的是单词。
  • @Jester 好的,我将两个数据的 db 更改为 dw。它显示 0 作为输出,为什么?

标签: assembly x86-16 emu8086


【解决方案1】:

除错-溢出。要手动处理此错误,请更改中断向量表中INT 0的地址

emu8086 会马上提出这样的建议,非常了不起!
解决方案是避免除法错误(由于除法的商无法放入指定寄存器AL 而导致的错误)!
您使用的字节大小除法 div tenAX 进行运算,并将商留在 AL 中,余数留在 AH 中。

一些错误(可能)会导致问题:

  • 您正在从一个充满字节 (mov ax, [si]) 的表中加载单词。
  • 您允许的红利比任务规定的更大 (cmp ax, 150)。

这将起作用:

    xor  dx, dx
    mov  cx, 9
l2: mov  al, [si]
    mov  ah, 0
    cmp  al, 50
    jb   l1
    cmp  al, 100
    ja   l1
    add  dx, ax
l1: inc  si
    loop l2

; At the end of the previous loop, `CX` is zero.
; We can use that for a digit counter instead of `BX`.
; Next division scheme will work fine for dividends up to 2550.

    mov  ax, dx     ; -> AX = 50 + 75 + 100 = 225
l3: div  ten        ; AX / 10  -> Quotient is in AL
    add  ah, 30h    ; Remainder is in AH
    push ax
    inc  cx
    mov  ah, 0
    cmp  al, 0
    jne  l3

l4: pop  dx
    mov  dl, dh
    mov  ah, 02h    ; DOS.PrintChar
    int  21h
    dec  cx
    jnz  l4 

【讨论】:

  • @SachinBhusal 您可以保留db 字节数据。请参阅我编辑的答案。
  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多