4. Arithmetic Operations
You can perform addition, subtraction, multiplication, and division in assembly language. A addition and subtraction are performed using the add
and sub
instructions, respectively. These instructions take two operands: destination and source. The add
instruction adds the source and destination and stores the result in the destination. The sub
instruction subtracts the source from the destination operand, and the result is stored in the destination. These instructions set or clear flags in the eflags
register, based on the operation. These flags can be used in the conditional statements. The sub
instruction sets the zero flag, (zf)
, if the result is zero, and the carry flag, (cf)
, if the destination value is less than the source. The following outlines a few variations of these instructions:
add eax,42 ; same as eax = eax+42 add eax,ebx ; same as eax = eax+ebx add [ebx],42 ; adds 42 to the value in address specified by ebx sub eax, 64h ; subtracts hex...