Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to find the minimum and maximum of three integers


This routine that shows how to find the minimum and maximum values of three integers using assembly code.

procedure MinMax(a, b, c: integer; var mn, mx: integer);
{-return min and max (a,b,c)}
  cmp eax,edx      // if a > b then
  jg @1            //   goto @1
  xchg eax,edx     // else swap(a,b)
  cmp eax,ecx      // if a < c then
  jg @2            //   goto @2
  xchg eax,ecx     // else swap(a,c)
  cmp ecx,edx      // if c > e then
  jg @3            //   goto @3
  xchg ecx,edx     // else swap(b,c)
  mov ecx,[ebp+8]  // get the address of max
  mov [ecx],eax
  mov ecx,[ebp+12] // get the address of min
  mov [ecx],edx
Author: Unknown
Contributor: Bruce Wernick
Added: 2014-01-22
Last updated: 2014-01-22

« Return to contents »