简体   繁体   中英

MASM Assembly, creating loops

 .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 ?
rejected byte cr, Lf, "Rejected", 0

    .code
_start:
main PROC

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

processing:
    cmp number,10
        jg message
    cmp number,-10
        jl message

message: output rejected


finish:
    INVOKE ExitProcess, 0

main endp
PUBLIC _start
        END

What i'm trying to accomplish: Read in a number one at a time, process that number and check if it is 0, if so, exit the program, if the number is > 10 or < -10 print a message "rejected." I'm have a lot of trouble creating my jump statements, how do I make the loop continue to process numbers until 0 ? Even when I enter a "valid" number, it still prints the message "rejected" but then exits the program. Maybe I can't have multiple jump statements after a compare ?

You put the loop in the wrong order. When 0 is entered you exit, otherwise you process it and THEN you want to repeat the loop until 0 is entered, optionally you have to print the message when the input was a wrong value.

     cmp number,0
     je  finish

processing:
    ...
    jmp forever    ; So everything is fine and you continue


message:
    output rejected
    jmp forever

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM