Find minimum of two unsigned valuesAssembler/8086

This small gem show how you can find the minimum of two unsigned numbers:

        if (b < a)  a = b;
The approach used here does not use any branches which may mess up your BTB (Branch Target Buffer)
;
; Find minimum of two unsigned values
;
; input:
;   eax = value a
;   ebx = value b
;
; output:
;   eax = smallest value
;
; destroys:
;   ebx, ecx
;   flags
;

        sub     ebx,eax
        sbb     ecx,ecx
        and     ecx,ebx
        add     eax,ecx
You can use this gem on 16 bit machines too, just use 16 bit registers. This gem comes from Agner Fog's Pentium optimization manual. Be sure to get this manual.
Gem writer: Agner Fog
last updated: 1998-03-16