I just made the following $Bswap macro. It performs the same task as BSWAP instruction on immediates.
The macro is working well:
%ECHO * $Bswap (12345678h)

%ECHO * $Bswap (78563412h)

* 2018915346	<- in hex 78563412

* 305419896 <- in hex 12345678

but ML still says:
error A2126: EXITM used inconsistently

It is weird, because the macro is working, isn't it?

Here's the macro:
$Bswap  MACRO   op:REQ

IFE $IsImm (op)
ECHO
ECHO * $Bswap MACRO error: the argument op has to be immediate
ECHO * interrupted by forcing error...
ECHO
.ERR
EXITM
ENDIF

$Bswapa = op AND 0FFh
$Bswapa = $Bswapa SHL 24t

$Bswapb = op AND 0FF00h
$Bswapb = $Bswapb SHL 8t

$Bswapc = op AND 0FF0000h
$Bswapc = $Bswapc SHR 8t

$Bswapd = op AND 0FF000000h
$Bswapd = $Bswapd SHR 24t

$Bswapresult TEXTEQU % ($Bswapa OR $Bswapb OR $Bswapc OR $Bswapd)
EXITM <$Bswapresult>
ENDM

P.S. I use some of Four-F's $IsXXX macros:
http://www.asmcommunity.net/board/viewtopic.php?t=14450

Thanks for these nice macros, 4f :)
Posted on 2004-09-18 05:38:35 by MazeGen
The macro is expecting to return a value - use "EXITM <>" to return nothing.

%ECHO * $Bswap ("asdf")

No temp is needed, but it is harder to read:
$Bswap MACRO op:REQ

IFE $IsImm (op)
ECHO
ECHO * $Bswap MACRO error: the argument op has to be immediate
ECHO * interrupted by forcing error...
ECHO
.ERR
EXITM <>
ENDIF

EXITM %(((op AND 0FFh) SHL 24) OR ((op AND 0FF00h) SHL 8) OR ((op AND 0FF0000h) SHR 8) OR ((op AND 0FF000000h) SHR 24))
ENDM
Posted on 2004-09-18 10:41:34 by bitRAKE
Yeah, it's working, thanks! BTW, tell me, how is it possible that the EXITM without brackets can have influence while compiling, when the compiler didn't take the EXITM between IFE-ENDIF in given examples :?

No temp is needed, but it is harder to read:

Since there is no advantage in such versions (except less lines), I prefer readability.


I got it - I used both EXITM without brackets and EXITM <$Bswapresult>. Didn't know that the compiler is able to check it.
Posted on 2004-09-18 13:10:18 by MazeGen