首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emu8086 -条件打印不会中断

Emu8086 -条件打印不会中断
EN

Stack Overflow用户
提问于 2016-03-04 10:27:00
回答 3查看 178关注 0票数 0

所以这是我的问题,每当我按'a‘满足条件时,它就会打印'a:’下面的文本,然后在'b:‘中打印文本。在不同的情况下,我该如何分手呢?谢谢:)

代码语言:javascript
复制
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:$"
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-03-04 10:35:34

是的,这就是你编码的行为。它只是从a:b:。因此,只需将jmps添加到末尾,它就会按需要工作。

代码语言:javascript
复制
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   
票数 0
EN

Stack Overflow用户

发布于 2016-03-04 10:33:56

程序流在int 21h指令之后继续--在您的情况下,这是b:标签上的代码。如果您不想这样做,那么在完成int指令之后,您需要跳到另一个地址:

代码语言:javascript
复制
...
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

票数 0
EN

Stack Overflow用户

发布于 2016-03-04 10:34:17

标签不是障碍,它只是程序中某个位置的名称,可以方便地访问所述位置。

与往常一样,如果您想要更改控制流,请使用某种分支指令,例如:

代码语言:javascript
复制
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:
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35793628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档