Return from JMP in x86 assembly?
I call PROC to check two values ββin an x86 16bits assembly and then jump if the value is greater than zero, so I do something like this:
TESTIT PROC
CMP AX,1
JG FOO
RET
TESTIT ENDP
FOO:
;do something
END FOO
MAIN:
CALL TESTIT
.EXIT
END MAIN
END
My questions are simple, how do I go back from FOO to the point in MAIN called TESTIT. I don't want to do JMP from FOO to MAIN, as this will call TESTIT again. When I try to put RET at the end of FOO, the command window gets stuck with a blinking cursor.
Note. I know this can be achieved with a pseudo op .IF ... .ENDIF
instead of JG, but I want to try to achieve the same result without a pseudo-operator that does some magic in the background, I don't know how to achieve it manually.
source to share
FOO must be called as a subroutine. To do this, invert your transition logic and use the CALL instruction to call FOO. Place a RET statement at the end of the FOO procedure.
TESTIT PROC
CMP AX,1
JLE BAR
CALL FOO
BAR:
RET
TESTIT ENDP
FOO:
;do something
RET
END FOO
MAIN:
CALL TESTIT
.EXIT
END MAIN
END
source to share