奇怪的结果导致部门装配8086

时间:2020-05-15 14:19:14

标签: assembly x86-16

我创建了一个计算器,该计算器获得两个数字,并返回大数与小数之间的除法结果的完整和剩余部分, 对于除法后的个位数结果,该程序对我来说很好用, 但是,当我得到的结果超过一位数时,或者在整个部分或其余部分时,我都能确定问题出在哪里,但我不明白为什么... 问题开始于〜Convert1〜标签,当我尝试将多位数除以10H时,我在ax和dx中得到错误的结果, 例如,当我的第一个数字为100而第二个数字为3时,我尝试将十六进制0021中的完整部分(33)除以十六进制000A中的(10),我得到ax值199C和dx值0009和i不明白为什么... D:



.MODEL SMALL
.STACK  100h
.DATA
msg1 db "Please Enter Your First Number:",'$'
msg2 db "Please Enter The Second Number:", '$'
msg3 db "The result of the division is:", '$'
resultstr db 12 dup ('$'),0DH
msg4 db "The rest of the division is:", '$'
reststr db 12   dup ('$'),0DH
Ten dw 10
num1 dw 0
num2 dw 0
num1str db 12,?,12 dup('$'),0DH
num2str db 12,?,12 dup('$'),0DH

.Code

start:
    mov ax, @data
    mov ds, ax
    ; Printing Message1 with a lineBreak
    lea dx, msg1
    mov ah, 09
    int 21H
    mov dl,0AH
    mov ah, 02
    int 21H

    ; Getting The first num1    
    mov ah, 0AH
    lea dx, num1str
    int 21H

    ; Printing Message1 with a lineBreak
    lea dx, msg2
    mov ah, 09
    int 21H
    mov dl,0AH
    mov ah, 02
    int 21H

    ; Getting The first num2    
    mov ah, 0AH
    lea dx, num2str
    int 21H

    mov cl,byte ptr num1str + 1 ; puting in cx the len of the num1str
    mov ch,0

    mov si, offset num1str + 2
    xor ax, ax
    FirstConvert: ; Here we convert the num1 String input from his ascii value into a intger value...
        mul Ten
        xor bx, bx
        mov bl, [si]
        sub bx, '0'
        add ax, bx
        inc si
     loop   FirstConvert

    add num1, ax ; after we calculate his intger value we put him in num1


    mov cl,byte ptr num2str+1 ; puting in cx the len of num2str
    mov ch,0

    mov si, offset num2str + 2
    xor ax, ax
    SecondConvert: ; Here we convert the num2 String inpurt from his ascii value into intger value ... 
        mul Ten
        xor bx, bx
        mov bl, [si]
        sub bl, '0'
        add ax, bx
        inc si
        loop    SecondConvert

    add num2, ax ;after we calculate his intger value we put him in num2
    mov ax, num1 ; In the next 5 lines im going to check who is the bigger number...
    mov bx,num2 ; ^^
    cmp ax,bx ; ^^
    jge BigNum1 ; The case num1 is bigger
    jmp BigNum2 ; The case num2 is bigger

    BigNum1: ; Here I first organize my numbers and then divide them and then send them to my converters to get their ascii value for the printing...
        mov ax,num1
        mov bx,num2
        div bx
        mov num1,ax ; using our values to keep the results. 
        mov num2,dx ; using our values to keep the results.
        jmp Convert1



    BigNum2: ; Here I first organize my numbers and then divide them and then send them to my converters to get their ascii value for the printing...
        mov ax,num2
        mov bx,num1
        div bx  
        mov num1,ax ; using our values to keep the results. 
        mov num2,dx ; using our values to keep the results. 
        jmp Convert1

    ; now im going to convert the integers to their ascii values for the print.
    ; first lets start with the intger part. 

    Convert1:
    lea si, resultstr ; Si pointing into my resultstr that im going to use for the print...
    xor ax,ax
    xor bx,bx
    mov ax, num1 ; Convert to ascii value
    cmp ax,10
    jl Low10
    mov bx, Ten
    div bx
    add dx,'0'
    mov [si],dx
    inc si
    cmp ax , 0 ; If ax == 0 that mean we dont need to convert anymore digits... 
    jg Convertor1 ; if ax!=0 go to Convertor1 that going to this action until we got all our digits..
    je Convert2

    Low10:
    add ax,'0'
    mov [si], ax
    jmp Convert2



    Convertor1: ; he same steps we took earlier
        cmp ax,10
        jl Low10
        xor dx,dx
        mov bx,Ten
        div bx
        add dx,'0'
        mov [si],dx
        inc si
        cmp ax,0
        jg Convertor1
        je Convert2

    Convert2: ; Now we doing the same procedure we did for the integer part of the division result
        lea di, reststr 
        mov ax,num2
        cmp ax,10
        jl Low10B
        xor dx,dx
        mov bx, Ten
        cmp ax, 0 ; in case we have zero rest.
        je zero
        div bx
        add dx,'0'
        mov [di],dx
        inc di
        cmp ax, 0
        jg Convertor2
        je TheEnd


        Low10B:
            add ax,'0'
            mov [di],ax
            jmp TheEnd

    Convertor2: ; Allmost same loops ecxept here in the last line we jump into the TheEnd procedure...
        cmp ax,10
        jl Low10B
        xor dx,dx
        mov bx,Ten
        div bx
        zero:
        add dx,'0'
        mov [di],dx
        inc di
        cmp ax,0
        jg Convertor2
        je TheEnd


    TheEnd: ; Here we printing our converted^2 results and 
        lea dx, msg3
        mov ah, 09
        int 21H
        lea dx, resultstr
        mov ah,09
        int 21H
        lea dx, msg4
        mov ah, 09
        int 21H
        lea dx, reststr
        mov ah, 09
        int 21H



    ;end the program
    mov ah, 4ch
    mov al, 0
    int 21H

END start



0 个答案:

没有答案
相关问题