Two sets of arithmetic instructions - for 64-bit integer and for double precision float numbers are demonstrated in the following tables on this page. But let's discuss some common features of arithmetic MMIX instruction set first.
All arithmetic operations in MMIX are executed strictly according to the basic MMIX format
<result> : = <operand1> <operation> <operand2>
For example, for integer subtraction (code 24) register $X is set to the result of $Y - $Z calculation.
Every integer arithmetic instruction has two modifications - for signed numbers and unsigned ones (mnemonics for the last have additional letter U). The main difference between these kinds of operations is that "unsigned" instructions don't test the results for overflow. The inequality for multiplication and division is more essential, but we shall not consider it here. And as usual in MMIX instruction set there are two serial codes for each operation; it allows to do this operation with register $Z or unsigned byte constant Z. So MMIX has 4 modifications for each integer arithmetic operation.
Not all arithmetic operations are presented in the tables below - some additional instructions exist in the comprehensive MMIX set. For example, 16ADD operation which calculates 16*$Y+$Z. Such commands may be very useful for practical programming, but can be omitted during primary familiarization without any loss.
Main integer arithmetic operations
Code | Mnemonic | Name |
Comments |
18 | MUL $X, $Y, $Z |
multiply |
the signed product of register Y by register Z is placed into register X; the result is tested for overflow |
19 | MUL $X, $Y, Z |
multiply |
the signed product of register Y by constant Z is placed into register X; the result is tested for overflow |
1A | MULU $X, $Y, $Z |
multiply unsigned |
the lower 64 bits of unsigned product of $Y by register Z is placed into $X (the upper 64 bit - in special register rH) |
1B | MULU $X, $Y, Z |
multiply unsigned |
the lower 64 bits of unsigned product of $Y by constant Z is placed into $X (the upper 64 bit - in special register rH) |
1C | DIV $X, $Y, $Z |
divide |
the signed quotient of register Y by register Z is placed into register X; the result is tested for overflow |
1D | DIV $X, $Y, Z |
divide |
the signed quotient of register Y by constant Z is placed into register X; the result is tested for overflow |
1E | DIVU $X, $Y, $Z |
divide unsigned |
combined number from rD and $Y is divided by register Z; the result is stored into register X (remainder - in rR) |
1F | DIVU $X, $Y, Z |
divide unsigned |
combined number from rD and $Y is divided by constant Z; the result is stored into register X (remainder - in rR) |
20 | ADD $X, $Y, $Z |
add |
the signed sum of register Y with register Z is placed into register X; the result is tested for overflow |
21 | ADD $X, $Y, Z |
add |
the signed sum of register Y with constant Z is placed into register X; the result is tested for overflow |
22 | ADDU $X, $Y, $Z |
add unsigned |
the unsigned sum of register Y with register Z is placed into register X; the result is not tested for overflow |
23 | ADDU $X, $Y, Z |
add unsigned |
the unsigned sum of register Y with constant Z is placed into register X; the result is not tested for overflow |
24 | SUB $X, $Y, $Z |
subtract |
the signed difference between register Y and register Z is placed into register X; the result is tested for overflow |
25 | SUB $X, $Y, Z |
subtract |
the signed difference between register Y and constant Z is placed into register X; the result is tested for overflow |
26 | SUBU $X, $Y, $Z |
subtract unsigned |
the unsigned difference between register Y and register Z is placed into register X; the result is not tested for overflow |
27 | SUBU $X, $Y, Z |
subtract unsigned |
the unsigned difference between register Y and constant Z is placed into register X; the result is not tested for overflow |
Now take a look at the table of float point arithmetic operations. As compared with the previous table this one seems to be very small: no modifications and no operations with constant are provided. Note also that codes of operations are not serial as for integer arithmetic instructions.
Main float arithmetic operations
Code | Mnemonic | Name |
Comments |
04 | FADD $X, $Y, $Z |
float add |
the floating point sum of registers Y and Z is placed into register X |
06 | FSUB $X, $Y, $Z |
float subtract |
the floating point difference of registers Y and Z is placed into register X |
10 | FMUL $X, $Y, $Z |
float multiply |
the floating point product of registers Y and Z is placed into register X |
14 | FDIV $X, $Y, $Z |
float divide |
the floating point quotient of registers Y and Z is placed into register X |
And the last table shows how to convert numbers from integer to float and backwards. A very useful FUN operation is added to the bottom of the table although it belongs to other kind of commands.
Current rounding mode is used for most of float point instructions such as FIX or FSQR (square root). But this regime can be directly set in the Y field
Y=1: ROUND_OFF Y=2: ROUND_UP Y=3: ROUND_DOWN Y=4: ROUND_NEAR
Converting numeric types
Code | Mnemonic | Name |
Comments |
05 | FIX $X, $Z |
convert floating to fixed | overflow is testing |
07 | FIXU $X, $Z |
convert floating to fixed unsigned |
overflow is not testing |
08 | FLOT $X, $Z |
convert fixed to floating | convert signed integer value from
register Z to float and store to $X |
09 | FLOT $X, Z |
convert fixed to floating |
convert signed integer value of
constant Z to float and store to $X |
0A | FLOTU $X, $Z |
convert fixed to floating unsigned | convert unsigned integer value from
register Z to float and store to $X |
0B | FLOTU $X, Z |
convert fixed to floating unsigned | convert unsigned integer value of
constant Z to float and store to $X |
02 |
FUN X$, $Y, Z$ |
float unordered |
check $Y and $Z for NAN and reset $X
to 0 if both are not NAN (1 otherwise) |
Examples:
- instruction ADD $2, $2, 10 adds 10 to register 2
- instruction SUB $1, $2, $3 stores the difference $2 - $3 to register 1
- instruction FMUL $1, $2, $3 multiply float values from registers 2 and 3; the result is save to register 1
- instruction FIX $1, 00, $2 is equivalent to Pascal operator $1:=trunc($2) and FIX $1, 04, $2 - to $1:=round($2)
Related topics:
"MMIX basics" page
|