Bob
Bob

Reputation: 1396

Assembly: Jumping Confusion

I'm using the Irvine32.inc library, and am having an issue with my L4 jump.

    L1:
    mov edx, offset optionPromptMsg
    call WriteString
    call ReadInt
    mov ebx, 1
    cmp eax, ebx
    je L2                    //if eax is 1, jump to l2, if eax is -1, jump l3
    mov ebx, -1
    cmp eax, ebx
    je L3
    mov ebx, -2
    mov ecx, 2
    cmp ebx, eax   //if eax is less than -2 or more than 2 jump to L4
    ja L4
    cmp eax, ecx
    ja L4
    L2: call NextScore

    L4: mov edx, offset optionErrorMsg
        call WriteString

    loop L1
    L3 : call WriteScore

No matter how I format it, for some reason everytime L2: call NextScore is called, immediantly afterward L4 is called and I can't figure out why. NextScore is as follows...

NextScore PROC USES esi

mov edx, offset scorePromptMsg
call WriteString
call ReadInt
mov ebx, 0
mov ecx, 100
cmp ebx, eax
ja L1
cmp eax,ecx
ja L1
jmp L2
L1:
    mov edx, offset scoreErrorMsg
    call WriteString
L2:
    mov scores[esi*4], eax
    inc esi

ret
NextScore ENDP

As you see, NextScore reads in a value from 0-100 then, unsuccessfully at this time, adds that value to an array scores. For some reason it only adds duplicates of one number throughout the entire array,but that's an entirely different issue. Any thoughts or ideas are most appreciated!

Upvotes: 0

Views: 51

Answers (1)

Jester
Jester

Reputation: 58762

The ret at the end of NextScore goes back exactly to L4 because every ret goes back to continue where the matching call left off. That is if you want to do something else, you need to add code before L4 that gets executed when NextScore returns (such as a jmp to wherever you want to go instead of L4):

Upvotes: 4

Related Questions