top decor
Instruction set Arithmetic operations


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

CodeMnemonicName Comments
18MUL $X, $Y, $Z multiply the signed product of register Y by register Z is placed into register X; the result is tested for overflow
19MUL $X, $Y, Z multiply the signed product of register Y by constant Z is placed into register X; the result is tested for overflow
1AMULU $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)
1BMULU $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)
1CDIV $X, $Y, $Z divide the signed quotient of register Y by register Z is placed into register X; the result is tested for overflow
1DDIV $X, $Y, Z divide the signed quotient of register Y by constant Z is placed into register X; the result is tested for overflow
1EDIVU $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)
1FDIVU $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)
20ADD $X, $Y, $Z add the signed sum of register Y with register Z is placed into register X; the result is tested for overflow
21ADD $X, $Y, Z add the signed sum of register Y with constant Z is placed into register X; the result is tested for overflow
22ADDU $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
23ADDU $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
24SUB $X, $Y, $Z subtract the signed difference between register Y and register Z is placed into register X; the result is tested for overflow
25SUB $X, $Y, Z subtract the signed difference between register Y and constant Z is placed into register X; the result is tested for overflow
26SUBU $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
27SUBU $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

CodeMnemonicName Comments
04FADD $X, $Y, $Z float add the floating point sum of registers Y and Z is placed into register X
06FSUB $X, $Y, $Z float subtract the floating point difference of registers Y and Z is placed into register X
10FMUL $X, $Y, $Z float multiply the floating point product of registers Y and Z is placed into register X
14FDIV $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

CodeMnemonicName Comments
05FIX $X, $Z convert floating to fixedoverflow is testing
07FIXU $X, $Z convert floating to fixed unsigned overflow is not testing
08FLOT $X, $Z convert fixed to floatingconvert signed integer value from
register Z to float and store to $X
09FLOT $X, Z convert fixed to floating convert signed integer value of
constant Z to float and store to $X
0AFLOTU $X, $Z convert fixed to floating unsignedconvert unsigned integer value from
register Z to float and store to $X
0BFLOTU $X, Z convert fixed to floating unsignedconvert 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)

To applet
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
 

  (C) 2002, Evgeny Eremin. rEd-MMI project documentation
1