Read this article, which gives two examples of instructions set architectures (ISAs). Look over how the different microprocessors address memory. Take note of similarities and differences of format, instructions and type of instructions, and addressing modes between these two as well as between these and the MIPS instructions of the previous sections.
All logical instructions presented in this section are executed in the, as the name already suggests, the arithmetic logic unit.
These instructions require two operands.
|and mask, destination||GAS Syntax|
|and destination, mask||Intel Syntax|
and performs a bit-wise
and of the two operands, and stores the result in destination.
movl$0x1,%edx; edx ≔ 1 movl$0x0,%ecx; ecx ≔ 0 andl%edx,%ecx; ecx ≔ edx ∧ ecx ; here ecx would be 0 because 1 ∧ 0 ⇔ 0
andcan be used to calculate the intersection of two “sets”, or a value representing a “mask”. Some programming language require that Boolean values are stored exactly as either
and rax, 1will ensure only the LSB is set, or not set.
andcan be used for a destination mod mask operation, that is the remainder of integer division. For that, mask has to contain the value 2n-1 (i. e. all lower bits set until a certain threshold), where 2n equals your desired divisor.
|or addend, destination||GAS Syntax|
|or destination, addend||Intel Syntax|
or instruction performs a bit-wise
or of the two operands, and stores the result in destination.
movl$0x1,%edx; edx ≔ 1 movl$0x0,%ecx; ecx ≔ 0 orl%edx,%ecx; ecx ≔ edx ∨ ecx ; here ecx would be 1 because 1 ∨ 0 ⇔ 1
orcan be used to calculate the union of two “sets”, or a value representing a “mask”.
|xor flip, destination||GAS Syntax|
|xor destination, flip||Intel Syntax|
Performs a bit-wise
xor of the two operands, and stores the result in destination.
movl$0x1,%edx; edx ≔ 1 movl$0x0,%ecx; ecx ≔ 0 xorl%edx,%ecx; ecx ≔ edx ⊕ ecx ; here ecx would be 1 because 1 ⊕ 0 ⇔ 1
xor rax, rax(or any GPR twice) will clear all bits. It is a specially recognized word. However, since
xoraffects flags it might introduce bogus dependencies.
side effects for
Performs a bit-wise inversion of argument.
movl$0x1,%edx; edx ≔ 1 notl%edx; edx ≔ ¬edx ; here edx would be 0xFFFFFFFE because a bitwise NOT 0x00000001 = 0xFFFFFFFE
notis frequently used to get a register with all bits set.