如何在此汇编代码中找到错误?

时间:2019-03-24 18:53:08

标签: assembly x86-16 emu8086

此程序将hexadec转换为新的编号基数(基数),出现错误,但似乎找不到。

;This program converts number from decimal
;to a new numbering base(radix)

.Model small
.stack 200
.data

    radix db 10; radix 10 for decimal
    num dw 0EFE4H;
    temp db 10 dup(?); used to stimulate stack

.code
        mov ax, num; load ax with number


        mov cx,0 ;clear digital counter
        xor bh,bh; clear bh
        mov bl,radix; set for decimal
        xor si,si; clear si register

dispx1:
       mov dx,00 ;clear dx
       div bx    ;divide dx:ax by 10
       mov temp[si],dl;save remainder
       inc si
       inc cx ;count remainder
       or ax,ax;test for quotient of zero
       jnz dispx1; if quotient is not zero


       dec si
dispx2:

        mov dl,temp[si]; get remainder
        mov ah,06h;select function 06h
        add dl,30h;converts to ASCII
        int 21h

        dec si
        dec cx;repeat for all digits
        jnz displx2
.exit
end

1 个答案:

答案 0 :(得分:1)

您的程序使用.Model small。这意味着DS段寄存器未设置为指向您的.data。您需要自己执行以下操作:

.Model small
.stack 200
.data
    radix db 10        ; radix 10 for decimal
    num   dw 0EFE4H    ;
    temp  db 10 dup(?) ; used to stimulate stack
.code
    mov ax, @data      ;Load data segment address to AX     ADD THIS!
    mov ds, ax         ;Move segment address to DS          ADD THIS!
    mov ax, num        ;Load AX with number