.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall,dwExitCode:DWORD
Include io.h
cr equ 0DH
Lf equ 0AH
.STACK 4096
.DATA
number dword ?
string byte 40 dup(?)
rejected byte ", Rejected",cr,0
positiveNumber byte ", Positive",cr,0
negativeNumber byte ", Negative",cr,0
numberOfPos byte "Positive Numbers: ",0
numberOfNeg byte "Negative Numbers: ",0
runningSum byte "Running Sum of Positive numbers: ",0
newline byte cr,Lf,0
numaschar byte 11 dup(?),0
numPosaschar byte 11 dup(?),0
numNegaschar byte 11 dup(?),0
sumasChar byte 11 dup(?),0
.code
_start:
sub ebx,ebx ; numberOfPos = 0
sub ecx,ecx ; numberOfNeg = 0
sub edx,edx ; runningSum = 0
forever:
input string, 40
atod string
cmp eax,0
je finish
cmp eax,10
jg invalid
cmp eax,-10
jl invalid
cmp eax,0
jg positive
jl negative
jmp jumpToMainLoop
positive:
inc ebx
add edx,eax
dtoa numaschar,eax
output numaschar
output positiveNumber
output newline
negative:
add ecx,1
dtoa numaschar,eax
output numaschar
output negativeNumber
output newline
invalid:
dtoa numaschar,eax
output numaschar
output rejected
output newline
finish:
dtoa numPosaschar, ebx
dtoa numNegaschar, ecx
dtoa sumasChar, edx
output numberOfPos
output numPosaschar
output newline
output numberOfNeg
output numNegaschar
output newline
output runningSum
output sumasChar
output newline
INVOKE ExitProcess, 0
PUBLIC _start
END
jumpToMainLoop:
jmp forever
我想要做的是创建一个前向引用,其中我只在循环结束时跳回主循环(永远)。现在,我只知道如果我在每个无效、正、负标签的末尾写上 `jmp jumpToMainLoop' 就可以跳回主循环。如何调整程序以使其仅在循环结束时跳转到永远?