[英]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." 我要完成的工作:一次读一个数字,处理该数字并检查它是否为0,如果是,则退出程序,如果该数字> 10或<-10,则打印一条消息“被拒绝”。 “ I'm have a lot of trouble creating my jump statements, how do I make the loop continue to process numbers until 0 ?
创建跳转语句时遇到很多麻烦,如何使循环继续处理数字直到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. 输入
0
,您退出,否则进行处理, THEN
您要重复循环直到输入0
,还可以选择在输入错误值时打印消息。
cmp number,0
je finish
processing:
...
jmp forever ; So everything is fine and you continue
message:
output rejected
jmp forever
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.