Logical instructions

This group contains instructions for bitwise logical operations which you, being a developer, already know. These are NOT, OR, XOR, and AND operations. However, while high-level languages do make a difference between bitwise and logical operators (for example, bitwise AND (&) and logical AND (&&) in C), they are all the same on the Assembly level and are quite commonly used in conjunction with the EFlags register (or RFlags on 64-bit systems).

For example, consider the following simple snippet in C that checks for a specific bit being set and conditionally executes certain code:

if(my_var & 0x20)
{
// do something if true
}
else
{
// do something else otherwise
}

It may be implemented in Assembly like this:

and dword [my_var], 0x20  ; Check for sixth bit of 'my_var'. 
; This operation sets ZF if the result
; is zero (if the bit is not set).
jnz do_this_if_true ; Go to this label if the bit is set
jmp do_this_if_false ; Go to this label otherwise

One of the many other applications of these instructions is the finite field arithmetic, where XOR stands for addition and AND stands for multiplication.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset