How to perform a forward reference in MASM assembly Language?

299 views Asked by At
.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

What I'm trying to do is create a forward reference in which I only jump back to the main loop(forever) at the end of the loop. Right now, I only know how to jump back to the main loop if I write `jmp jumpToMainLoop' at the end of each label invalid, positive, negative. how do I adjust the program so that it only jumps to forever at the end of the loop?

1

There are 1 answers

0
Sep Roland On
jmp jumpToMainLoop

This is equivalent jmp forever.

Right now, I only know how to jump back to the main loop if i write `jmp jumpToMainLoop' at the end of each label invalid, positive, negative.

Why don't you just write jmp forever at those 3 places (right after output newline!