我的问题是它没有比较第一个数字是否大于第二个数字..它只执行我打印字符串的部分
mov ah,9
lea dx,str1
int 21h ;Write string at DS:DX to standard output
mov ah,1
int 21h ;Read character from standard input into AL
sub al,30h ;al = character - '0'
mov num1,al ;num = character - '0'
mov ah,9
lea dx,str2
int 21h ;Write string at DS:DX to standard output
mov ah,1
int 21h ;Read character from standard input into AL
mov al,2
cmp num1,al ;Is num1 greater than 2?
jg sum ; yes, goto sum
; no
mov ah,9
lea dx,str3
int 21h ;Write string at DS:DX to standard output
jmp exit
sum:
add num1,al ;num1 = num1 + AL = num1 + 2
mov ah,9
lea dx,new
int 21h ;Write string at DS:DX to standard output
mov ah,9
lea dx,num1
int 21h ;Write string at DS:DX to standard output
jmp exit
exit:
答案 0 :(得分:0)
你写过这个
cmp num1,al ;Is num1 greater than 2?
jg sum ; yes, goto sum
; no
你正在接受cmp语句的错误含义
正确的含义和陈述(对于这个场景)是
cmp num1,al ;Is 2 lesser than num1?
jl sum ; yes, goto sum
; no
我修改了你的代码,现在它就像这样
org 100h
jmp start
str1 dw 'Provide Input',10,13,'$'
str2 dw 'Provide another input',10,13,'$'
str3 dw 'First is greater',10,13,'$'
new dw 'Second is greater',10,13,'$'
num1 db ?
start:
mov ah,9
lea dx,str1
int 21h ;Write string at DS:DX to standard output
mov ah,1
int 21h ;Read character from standard input into AL
sub al,30h ;al = character - '0'
mov num1,al ;num = character - '0'
mov ah,9
lea dx,str2
int 21h ;Write string at DS:DX to standard output
mov ah,1
int 21h ;Read character from standard input into AL
sub al,30h ;al = character - '0'
cmp num1,al ;Is al lesser than num1?
jl sum ; yes, goto sum
; no
mov ah,9
lea dx,str3
int 21h ;Write string at DS:DX to standard output
jmp exit
sum:
add num1,al ;num1 = num1 + AL = num1 + al
mov ah,9
lea dx,new
int 21h ;Write string at DS:DX to standard output
exit:
MOV AH,4CH
INT 21H
现在尝试以这种方式首先输入2比5,请参阅输出。现在再次运行它并输入5比2的输入。当你自己运行它时,你会了解更多。