H
H
HexUserHex2020-12-01 10:35:10
assembler
HexUserHex, 2020-12-01 10:35:10

An example of using logical operations AND, OR, TEST in assembler?

Greetings,

Can I have an example of using logical operations in assembler?
As far as I understand, they are used to perform bit inversion, BUT I don’t understand when this may be needed in real tasks and for what (I will be glad to see an example)?

If there are people who are fluent in asm, then explain :)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vladimir Kuts, 2020-12-01
@HexUserHex

An example is the storage of flags of certain states.
In order not to use a whole byte to store one state (0 or 1), we take a byte and set a certain flag - for example, in a certain bit:

mov ah, myflag
or ah, b00001000 # установили флаг
mov myflag, ah   # обратно сохранили в переменную
...
mov ah, myflag  # берем обратно нашу переменную
and ah, b00001000 # и проверяем наше состояние
jz прыгнули_ если_флаг_равен_0
...
mov ah, myflag  # берем обратно нашу переменную
and ah, b00000010 # проверяем наше состояние в каком-то другом бите
jz прыгнули_ если_флаг_равен_0

Thus - in one byte we store 8 states
And these states - can be, for example - a kind of two-dimensional matrix - for example, for playing a sea battle 10x10 where 1 is the presence of a ship hull in a cell 0 - absence
And instead of storing 10 * 10 = We will store 100 bytes 10 * 10 // 8 = 12 + 1 = 13 bytes, taking into account the remainder
of 13 bytes versus 100 bytes - the savings are significant, especially if we have a resource limit (microcontrollers)

1
15432, 2020-12-01
@15432

most common are boolean conditions, combining multiple conditions
if((var & 1) == 1) {} ... can become TST
if(var1 == 0 && var2 == 1) can use AND
and so on

I
imdeveloper, 2016-11-08
@Pavel_Proca

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

Add to head

I
iBird Rose, 2016-11-08
@iiiBird

indicated this?

<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

S
Sergey, 2016-11-08
@Shull

What is your mobile resolution? It happens that in mobile phones with high resolution, the browser takes the mobile screen for a desktop monitor.
If this is the problem, then look at the solution here: "Preparing an adaptive website for Retina displays"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question