如何在 MASM 汇编语言中执行前向引用


.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"无效,正,负。如何调整程序,使其仅在循环结束时跳转到永久?

jmp jumpToMainLoop

这相当于jmp forever.

现在,我只知道如何跳回到主循环,如果我在每个标签的末尾写"jmp jumpToMainLoop"无效,正,负。

你为什么不直接在这 3 个地方写jmp forever(就在output newline之后!

最新更新