Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write an if statement in x86 assembly language?

Is it possible to mimic an if-statment in x86 assembly language (using masm syntax)? I want to do something like this in x86 assembly language, but I'm not sure which operator I should use to mimic an if-else statement. Should I use the jl instruction, or the cmp instruction, or some other instruction?

int i = 2;
int j = 3;
if(i > j){
    i = 1;
}
else{
    i = 4;
}
like image 766
Anderson Green Avatar asked Oct 19 '25 02:10

Anderson Green


1 Answers

A combination of cmp and jcc (that is, conditional jump) instructions will do. Look up your CPU manual.

like image 131
Alexey Frunze Avatar answered Oct 21 '25 21:10

Alexey Frunze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!