High-level statement if in the Assembly
How to write a boolean operator if the statement is in Assembly? For example, in C we have logical functions AND and OR, say:
Written in C
if((A >= B) && ( C < D)) {
A = A+1;
C = C*C;
}else
C = C - 1;
A = C;
I don't know if this is correct, but in assembly I will translate it like this:
Translated in assembly
if: cmp RA,RB
jl else
cmp RC,RD
jge else
inc RA
mul RC,RC
jmp endif
else: dec RC
mov RA,RC
endif:
I need your help, what if I have an if ((A> = B) || (C <D)) ?, OR function, what changes will be applied? I saw that the assembly also has logical operators (AND, OR, XOR), is it possible for us in this case? Could you describe an example of both cases?
source to share
what if i have
if((A >= B) || ( C < D))
You can follow the same approach as your original code after applying De Morgan's Law :
if(!((A < B) && ( C >= D)))
I saw that the assembly also has logical operators (AND, OR, XOR), is it possible for us in this case?
In that case, you might. However, this will no longer be equivalent to your C code, because the operators ||
and &&
use short-circuit evaluation .
source to share