## ldmxcsr - load MXCSR register

    MXCSR = operand

The ldmxcsr instruction loads the MXCSR register from a 32 bit memory address. The default value os 0x1f80.

### MXCSR Register

Bit(s) | Purpose
0 | Invalid operation flag
1 | Denormal flag
2 | Divide by 0 flag
3 | Overflow flag
4 | Underflow flag
5 | Precision flag
6 | Denormals are zeros
7 | Invalid operand mask
8 | Denormalized operand mask
9 | Divide-by-zero mask
10 | Overflow mask
11 | Underflow mask
12 | Precision mask
13-14 | Rounding control
15 | Flush to 0
16-32 | Leave these as 0

The lowest 6 bits of the MXCSR register are flags indicating the status of the latest operation. You could possibly wish to examine the status after an instruction to determine whether an underflow or overflow occurred.

Bits 6 through 15 of the MXCSR register control various aspects of the floating point instructions. Of particular interest in the 2 bit field in bits 13-14 which control rounding. Using 00 for this field rounds the result to the closest value. 01 means to round down and 10 means round up. Finally 11 means round toward 0. The default value 0x1f80 sets the precision mask, sets rounding to round to the closest value, and enables a variety of floating point exceptions. I suggest leaving bits 7-12 set and modifying the rounding control bits only, while leaving the register set to 0x1f80 when you exit from code which needs to modify it.

    closest: dd     0x1f80
    down:    dd     0x3f80
    up:      dd     0x5f80
    to_zero: dd     0x7f80

             ldmxcsr [down]            ; prepare to round down
             ldmxcsr [up]              ; prepare to round up
             ldmxcsr [to_zero]         ; prepare to round towards zero
             ldmxcsr [closest]         ; restore to the default

### flags: none