UMBC CMSC 313

 


Comparing and Branching Operations

The comparisons will be done in the FPU and the decision to branch will be done in the CPU. This must be done in two steps.

FPU Compare Instructions
fcom[p] mem32 or mem64 ; compare ST0 to operand [and pop]
fcom[p] STn ; compare ST0 to STn [and pop]
fcom[p]   ; compare ST0 to ST1 [and pop]
fcompp   ; compare ST0 to ST1 and pop twice
ficom[p] mem16 or mem32 ; compare ST0 to converted integer operand [and pop]
ftst   ; compare ST0 to 0.0

Transferring the FPU Status Word to Flags

The FPU will compare and set bits in an FPU register (status word). These must then be transferred to the Flags Register in the CPU.
StatWd DW ? ; defined in the .DATA Segment
  ; ...    
  fld B4  
  fld C4  
  fcom    
  fstsw StatWd ; Store status word in StatWd
  mov ax, StatWd  
  sahf   Transfer ah into flags register
  jbe OrderOK ; Note unsigned jump
  fxch    
OrderOK      
  fstp A4  
  fcomp ST ; pop smaller item

©2004, Gary L. Burt