call subroutines conditionally in assembly

The clean way to do it is simply:

    cmp bx,0
    jnz notzero
    ; handle case for zero here
    jmp after_notzero
notzero:
    ; handle case for not zero here
after_notzero:
    ; continue with rest of processing

I know no better way for an if-else situation. Ok, if both branches must return directly afterward, you can do:

    cmp bx,0
    jnz notzero
    ; handle case for zero here
    ret

notzero:
    ; handle case for not zero here
    ret

If some processing must take place before the ret (e.g. popping values previously pushed), you should use the first approach.

Leave a Comment