Matan
Matan

Reputation: 591

call equivalent of jump conditions

in 80x86 assembly, is there an equivalent way to use 'call' like we do with 'je' 'jl' 'jg' 'jne' ? i want to 'call' only if a condition is met .. ?

i want to implement :

cmp   eax, 1
je    something
; and continuing from here
; ....
; ...
jmp   end
something:
    ret

using je

thanks !

Upvotes: 1

Views: 751

Answers (4)

karlphillip
karlphillip

Reputation: 93410

How about jumping directly to the address of the call?

cmp   eax, 1
je    address_of_the_call
; else code
; ....
; ....

Upvotes: 1

aib
aib

Reputation: 46951

You could also push the return address and jump.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490108

Not directly, no -- the call instruction is always unconditional. Depending on what you're doing with je/jl/etc., you may be able to get a (somewhat) similar effect with an indirect call like call [ebx], and having a jump table that contains the address of a 'null' procedure that will be called when ebx=0:

.code
proc1 proc
    ; whatever
null_proc::
    ret
proc1 endp

proc2 proc
   ; whatever
   ret
proc2 endp

main proc
    lea ebx, jmp_table[eax]
    call [ebx]
main endp

.data

jmp_table dd null_proc, proc1, proc2

end

Upvotes: 4

E.Freitas
E.Freitas

Reputation: 532

Use the appropriate jump command to jump to the call statement? Have you tried that already?

Upvotes: 2

Related Questions