2013-12-19 47 views
0

我寫了以下代碼來測試用戶輸入是否在0和9之間。
不幸的是,當用戶輸入qsu時,它將跳轉到cont
PS:invcont是標籤。爲什麼跳到錯誤的地方?

.model small 
.stack 
.data 
    msg db 0ah,0dh,'Enter TWO odd integer values (0 to 9): $' 
    invalid db 0ah,0dh,'The number is not an odd number.$' 
    firstnum db ? 
    secondnum db ? 
    result db 0ah,0dh,'The average of the input values is: $' 
.code 
main proc 
    mov ax,@data 
    mov ds,ax 
loopin: 
    mov ah,09h 
    lea dx,msg 
    int 21h 

    mov ah,01h 
    int 21h 

    sub al,30h 
    mov firstnum,al 

    sub ah,ah 
    mov bl,2 
    div bl 
    cmp ah,0 
    je inv 
    jmp cont 
inv: 
    mov ah,09h 
    lea dx,invalid 
    int 21h 
    jmp loopin 
cont: 
    mov ah,02h 
    mov dl,',' 
    int 21h 

    mov ah,01h 
    int 21h 

    sub al,30h 
    mov secondnum,al 

    sub ah,ah 
    mov bl,2 
    div bl 
    cmp ah,0 
    je inv 

    sub ah,ah 
    mov al,firstnum 
    add al,secondnum 
    mov bl,2 
    div bl 
    mov bh,ah 

    mov ah,09h 
    lea dx,result 
    int 21h 

    add al,30h 
    mov ah,02h 
    mov dl,al 
    int 21h 

    mov ah,02h 
    mov dl,'.' 
    int 21h 

    sub ah,ah 
    mov al,bh 
    mov bl,5 
    mul bl 
    add al,30h 

    mov ah,02h 
    mov dl,al 
    int 21h 

    mov ah,4ch 
    int 21h 
main endp 
end main 
+3

你能粘貼完整的代碼嗎?或者至少是標籤及其位置 – hcf

+0

'cont'是否定義在'jbe cont'旁邊? – szx

回答

0

這應該是你的測試代碼嗎?

sub al,30h 
mov firstnum,al 

sub ah,ah 
mov bl,2 
div bl 
cmp ah,0 
je inv 
jmp cont 

絕對不會檢查輸入是一個數字。試試這個:

sub al,30h 
jb notanumber 
cmp al,9 
ja notanumber 
mov firstnum,al 
[…] 
相關問題