Unary Arithmetic Instructions
Unary arithmetic instructions are those that operate on a single operand. These instructions perform arithmetic operations directly on the operand without requiring a second operand.
1 Neg (Negation)
The Neg instruction negates (changes the sign of) the operand. It computes the two's complement of the operand, effectively multiplying it by -1.
Syntax:
Intel Syntax:
neg operandmov eax, 10 ; Load 10 into EAX
neg eax ; Negate the value of EAX (result: -10)AT&T Syntax:
neg destinationmovl $10, %eax # Load 10 into EAX
negl %eax # Negate the value of EAX (resulting in -10)
2 INC (Increment)
The inc instruction increments the value of the operand by 1.
Syntax:
Intel Syntax:
inc operandmov ebx, 5 ; Load 5 into EBX
inc ebx ; Increment the value of EBX by 1 (result: 6)AT&T Syntax:
inc destinationmovl $10, %eax # Load 10 into EAX
incl %eax # Increment the value of EAX by 1
3 DEC (Decrement)
This instruction decrements the value of the operand by 1.
Syntax:
Intel Syntax:
dec operandmov ecx, 8 ; Load 8 into ECX
dec ecx ; Decrement the value of ECX by 1 (result: 7)AT&T Syntax:
dec destinationmovl $20, %ebx # Load 20 into EBX
decl %ebx # Decrement the value of EBX by 1
Binary Arithmetic Instructions
These instructions allow for the manipulation of numerical data, performing operations such as addition, subtraction, multiplication, and division.
1 Add (Addition)
Adds the value of the source operand to the destination operand and stores the result in the destination.
Syntax:
Intel Syntax:
add rax, rbx ; Add the contents of RBX to RAX and store the result in RAX
2 Sub (Subtraction)
Subtracts the value of the source operand from the destination operand and stores the result in the destination.
Syntax:
Intel Syntax:
sub rdx, rcx ; Subtract the contents of RCX from RDX and store the result in RDX
3 IMul(Signed multiplication)
Performs signed multiplication of the destination and source operands and stores the result in the destination.
Syntax:
Intel Syntax:
imul rsi, rdi ; Multiply the contents of RDI by RSI and store the result in RSI
4 IDIV (Signed Division)
Performs signed division of the DX:AX register pair (RDX:RAX for 64-bit division) by the operand, storing the quotient in AX register (or RAX for 64-bit division) and the remainder in DX register (or RDX for 64-bit division).
Syntax:
Intel Syntax:
mov rax, 100 ; Load 100 into RAX
idiv rcx ; Divide RDX:RAX by RCX
5 Mul (Unsigned Multiplication)
Performs unsigned multiplication of the AX register (EAX register for 32-bit, RAX for 64-bit) by the source operand, storing the results in AX register (EAX for 32-bit, ). The operand can be a register or a memory location.
6 Div (Unsigned Division)
Performs unsigned division of the DX:AX register pair by the operand, storing the quotient in AX and the remainder in DX.

Join the discussion
Sign in with your account to post comments, reply to others, and participate in the conversation.
Login to Comment