所以这是我的问题,每当我按'a‘满足条件时,它就会打印'a:’下面的文本,然后在'b:‘中打印文本。在不同的情况下,我该如何分手呢?谢谢:)
cmp byte ptr [temp+2], 'a' ;condition
je a
cmp byte ptr [temp+2], 'b' ;condition
je b
a:
mov dx, offset msgA ;land
mov ah, 09
int 21h
b:
mov dx, offset msg14 ;water
mov ah, 09
int 21h
ret
msgA db 10, 13, " Land:$"
msg14 db 10, 13, " Water:$"发布于 2016-03-04 10:35:34
是的,这就是你编码的行为。它只是从a:到b:。因此,只需将jmps添加到末尾,它就会按需要工作。
cmp byte ptr [temp+2], 'a' ;condition
je a
cmp byte ptr [temp+2], 'b' ;condition
je b
jmp finish ; --- add this for the case, that neither 'a' nor 'b' was the input
a:
mov dx, offset msgA ;land
mov ah, 09
int 21h
jmp finish ; --- JMP to the end - do not fall through
b:
mov dx, offset msg14 ;water
mov ah, 09
int 21h
jmp finish ; --- JMP to the end - in this case not necessary, but just in case you'd add more cases
finish:
ret 发布于 2016-03-04 10:33:56
程序流在int 21h指令之后继续--在您的情况下,这是b:标签上的代码。如果您不想这样做,那么在完成int指令之后,您需要跳到另一个地址:
...
a:
mov dx, offset msgA ; land
mov ah, 09
int 21h
jmp done ; program continues here after the `int` instruction
b:
mov dx, offset msg14 ; water
mov ah, 09
int 21h
done:
ret
...由于完成时所做的一切都是从过程中返回,所以您也可以简单地使用ret而不是jmp。
发布于 2016-03-04 10:34:17
标签不是障碍,它只是程序中某个位置的名称,可以方便地访问所述位置。
与往常一样,如果您想要更改控制流,请使用某种分支指令,例如:
a:
mov dx, offset msgA ;land
mov ah, 09
int 21h
jmp done
b:
mov dx, offset msg14 ;water
mov ah, 09
int 21h
done:https://stackoverflow.com/questions/35793628
复制相似问题