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.
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.
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.
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.
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 ...
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With