首页 文章

汇编:最大数量:不正确比较

提问于
浏览
2
.MODEL SMALL
.STACK 100h
.data
bigger db 0
mensaje db 0AH,0DH,'Finding the biggest number','$'
mensaje1 db 0AH,0DH,'Write 5 numbers to compare','$'
mensaje2 db 0AH,0DH,'Number: ','$'
resultadomayor db 10,13,'the biggest number is: ','$'
.code
start proc far 
    MOV AX,@DATA
    MOV DS,AX
    mov cx,5
    MOV DX,OFFSET MENSAJE
    MOV AH,09
    INT 21H
    MOV DX,OFFSET MENSAJE1
    MOV AH,09
    INT 21H
ciclo: call iniciociclo
 dec cx
jne ciclo
    call imprimirmayor

    MOV AH,4CH
    INT 21H  
start endp
;
bucle proc near

 MOV DX,OFFSET MENSAJE2
 MOV AH,09
 INT 21H
 MOV AH,01
 INT 21H
 cmp bigger,al
 jnb masgrande

 masgrande: 
 mov bigger,al
 ret
bucle endp
;
printbiggest proc near

MOV DX,OFFSET resultadomayor
MOV AH,09
INT 21H
mov dx,offset bigger
mov ah,09
int 21h
printbiggest endp
end start

当我运行我的程序时,它只显示最大的数字输入 . 它不会比较或保存在最后一个之前写的其他数字 . 我研究把它作为一个数组,但我的老师要求我插入数字而不是给出数字 . 用户应该给出数字,而不是程序员 . 所以我没有找到如何在数组上插入数字 . 这就是为什么我比较数字和数字 . 顺便说一下,这是组装8086 .

2 回答

  • 0

    你的问题在这里:

    cmp bigger,al
    jnb masgrande
    
    masgrande: 
    mov bigger,al
    

    该代码将始终将值复制到变量 bigger ,因为 jnb 指令不会导致跳过任何代码 . 重新排列这样的说明:

    cmp bigger,al
    jnb masgrande
    mov bigger,al
    masgrande:
    
  • 1

    如上所述,你应该把线放在正确的位置,你的代码只是“飞过”条件(尽量避免无意义的标签) . 也尝试使用JB而不是JNA .

    cmp bigger,al
    jnb masgrande
    ;missing
    masgrande: 
    mov bigger,al
    
    CMP al, biggest
    JB NOT_BIGGEST
    MOV biggest, al
    NOT BIGGEST:
    ;keep your program here
    

相关问题