The api mentions using two macros named min and max. Does anyone have a masm32 version of these macros? They seem very simple but I have never made a masm macro before.
Here is the definition from the api:
Here is the definition from the api:
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
max macro a,b ; returns the max in EAX
ifdifi <b>,<eax>
ifdifi <eax>,<a>
mov eax,a
endif
.if eax<b
mov eax,b
.endif
else
.if eax<a
mov eax,a
.endif
endif
endm
min macro a,b ; returns the min in EAX
ifdifi <b>,<eax>
ifdifi <eax>,<a>
mov eax,a
endif
.if eax>b
mov eax,b
.endif
else
.if eax>a
mov eax,a
.endif
endif
endm
Thanks Ultrano. Nice form.
rdaneel,
Why stop with just two terms? Why not find the max/min of several terms? Ratch
Why stop with just two terms? Why not find the max/min of several terms? Ratch
.686
;.MMX
;.K3D
;.XMM
.MODEL FLAT,STDCALL
option casemap :none ; case sensitive
@ EQU OFFSET
; #########################################################################
.NOLIST
; INCLUDE \MASM32\INCLUDE\MYSTUFF.INC
; INCLUDE \MASM32\INCLUDE\WND32.INC
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
.LIST
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
MIN MACRO P1,P2:VARARG ;P1=REG,P2=TERMS
LOCAL L1,MIN$
L1=0
FOR ARG,<P2>
CMP P1,ARG
JL @CatStr(MIN$,%L1) ;to unique label
MOV P1,ARG
@CatStr(MIN$,%L1): ;unique label
L1=L1+1
ENDM
ENDM
.DATA
ALPHA DWORD 3
.CODE
MAIN:
MIN EAX,0,ECX,[ALPHA],6
MIN EBX,7,@ ALPHA,9,2
END MAIN