Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly language je jump function

Tags:

I am trying to find online the usage of the assembly language function "je". I read that je means jump if equal and that is exactly what I want. What is the actual usage of this function, or in other words, how to I type this function to check a value and jump if it is equal to something?

Please let me know.

BTW, I am using NASM if that makes a difference.

like image 786
QAH Avatar asked Oct 17 '09 19:10

QAH


People also ask

What is jump above in assembly language?

Jump if Above (unsigned comparison)EditLoads EIP with the specified address, if the minuend of the previous cmp instruction is greater than the subtrahend . ja is the same as jg , except that it performs an unsigned comparison.

What type of instruction is jump?

1. Jump Instructions – The jump instruction transfers the program sequence to the memory address given in the operand based on the specified flag. Jump instructions are 2 types: Unconditional Jump Instructions and Conditional Jump Instructions.

Why do we use jump statements?

Jump statements can be used to modify the behavior of conditional and iterative statements. Jump statements allow you to exit a loop, start the next iteration of a loop, or explicitly transfer program control to a specified location in your program.


2 Answers

Let's say you want to check if EAX is equal to 5, and perform different actions based on the result of that comparison. An if-statement, in other words.

  ; ... some code ...    cmp eax, 5   je .if_true   ; Code to run if comparison is false goes here.   jmp short .end_if .if_true:   ; Code to run if comparison is true goes here. .end_if:    ; ... some code ... 
like image 84
bcat Avatar answered Oct 06 '22 16:10

bcat


This will jump if the "equal flag" (also known as the "zero flag") in the FLAGS register is set. This gets set as a result of arithmetic operations, or instructions like TEST and CMP.

For example: (if memory serves me right this is correct :-)

cmp eax, ebx    ; Subtract EBX from EAX -- the result is discarded                 ; but the FLAGS register is set according to the result. je .SomeLabel   ; Jump to some label if the result is zero (ie. they are equal).                 ; This is also the same instruction as "jz".
like image 28
asveikau Avatar answered Oct 06 '22 15:10

asveikau