Arithmetic Instructions

MSIL supports the standard arithmetic instructions. The operands of the arithmetic operation are retrieved from the evaluation stack and replaced with the result. For example, the add instruction has two addends, which are removed from the evaluation stack and replaced with their sum.

Table 14-8 lists the common arithmetic instructions. The third column is the number of operands consumed from the evaluation stack during the instruction.

Table 14-8. Arithmetic instructions

Instruction

Description

Number of Operands

add

Addition

2

sub

Subtraction

2

mul

Multiplication

2

div

Division

2

rem

Remainder

2

neg

Negate

1

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.