Assembly MASM组件跳转指令打印问题

Assembly MASM组件跳转指令打印问题,assembly,masm,Assembly,Masm,当这个程序读取一个正数时,为什么它同时打印“正数”和“负数”消息,而我需要它只打印“正数”消息 感谢您的帮助。谢谢 查看标签消息2后面的代码-其中没有jmp指令。因此,在打印“肯定”后,代码“通过”到下一个案例,然后打印“否定” 我猜您打算跳转到永远或完成我可以把我的跳转到最上面的语句放在哪里,这样我只需要将它放在一个位置,而不是从多个位置跳转?有可能吗?使用call指令,可以避免多次使用jmp。然后,只能使用ret指令执行向后跳转。@AmberBexley-仔细查看您的代码,我可能会在标签消息

当这个程序读取一个正数时,为什么它同时打印“正数”和“负数”消息,而我需要它只打印“正数”消息

感谢您的帮助。谢谢


查看标签
消息2
后面的代码-其中没有jmp指令。因此,在打印“肯定”后,代码“通过”到下一个案例,然后打印“否定”


我猜您打算跳转到
永远
完成

我可以把我的跳转到最上面的语句放在哪里,这样我只需要将它放在一个位置,而不是从多个位置跳转?有可能吗?使用call指令,可以避免多次使用jmp。然后,只能使用ret指令执行向后跳转。@AmberBexley-仔细查看您的代码,我可能会在标签
消息3
之前添加
jmp jumpToTop
作为代码行。当然,您正在跳转到一个位置,然后再跳转-如果您的代码只是跳转到
永远
,那么它的效率会稍高一些,但是如果您只是将jmp转到
跳转到
永远
,那么它更容易阅读(imho)。无论是向前还是向后跳转,在执行
message2
标签后面的代码并在
message3
标签前面的代码后,您(或多或少-请参见van Uitkon的注释)都需要一个。@vanUitkon-Hmmm.是的,您可以这样做。我对这种措施的执行时间和可读性感到悲观。第一个与本例无关,第二个与风格有关。除非我需要,否则我宁愿不要胡闹。像这样使用call/ret也是一种伤害初学者头脑的好方法。另请参见:过早优化。@vanUitkon请您写出注释代码对我来说会不会太麻烦?我不熟悉您描述的方法,因为我今天才开始编写汇编。
   .386
   .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD 
Include io.h
cr     equ 0DH
Lf     equ 0AH

       .STACK 4096
       .DATA

string byte 40 Dup (?)
number dword ?

runningSum dword 0

rejected byte " , Rejected", 0
positive byte cr, Lf, "Positive",0
negative byte cr, Lf, "Negative",0

numaschar byte 11 dup(?),0
newline byte cr,Lf,0

    .code
_start:

forever: input string, 40
         atod string
         mov number, eax
         cmp number,0
         jne processing
         je finish

processing:
    cmp number,10
        jg message

    cmp number,-10
        jl message

    cmp number,10
        jle not_rejected1

    cmp number,-10
        jge not_rejected2

    jmp jumpToTop

message: dtoa numaschar,number
         output numaschar
         output rejected
         output newline

not_Rejected1: cmp number, -10
                 jge processing2

not_Rejected2: cmp number,10
                 jle processing2

processing2:   cmp number, 0
                 jg addInstruct
                 jl subInstruct


addInstruct: add ebx, 1
             add edx,number
             jmp message2

subInstruct: add ecx, 1
             jmp message3

message2: dtoa numaschar, number
          output positive
          output newline

message3: dtoa numaschar, number
          output negative
          output newline


jumpToTop: jmp forever


finish:
    INVOKE ExitProcess, 0

PUBLIC _start
        END