Verify dual state in assembly

I start the assembly, I use nasm to build the code, I try to process the string in memory and change it, I want to check if the byte is in a certain range (ascii), so I can decide what to do with it, I don’t I can understand how to check if a value is in a certain range, I all know the different types of transition flags, but how can I combine 2 cmp expressions?

my question is: how can I create something like this in an assembly?

if (x>=20 && x<=100)
     do something

Thank you so much!

+3
source share
4 answers

Depending on which syntax you are using, and if it xis in a register eax, something like this:

cmp  %eax, 20
jl   ELSE
cmp  %eax, 100
jg   ELSE
#do something
jmp  END

ELSE:
#do else

END:
+4
source

, , :

     sub  %eax,  20
     cmp  %eax,  80
     ja   END
     // do something
END: ret

. [20,100] - [0,80]; .

, C:

unsigned int upperBound = 100;
unsigned int lowerBound = 20;
if (yourValue - lowerBound <= upperBound - lowerBound) {
    // do something
}
+20

You can try to compile it from a higher level language (C / C ++ / ...) with optimization at high (-O3 for gcc) and see what the compiler (objdump) generates. It should generate very efficient code.

+1
source

Like this?

x<20
if false jump to ELSE
x>100
if false jump to ELSE
  do something
  jump to ENDIF
:ELSE
  do something else
:ENDIF

Or do you mean using only one assembly instruction?

0
source

Source: https://habr.com/ru/post/1796337/


All Articles