The MASM Forum

General => The Campus => Topic started by: daydreamer on November 30, 2021, 01:11:01 AM

Title: Is it possible to make alternative macro?
Post by: daydreamer on November 30, 2021, 01:11:01 AM
Alternative macro similar to. If. Else.endif
But when using test different bits?
Title: Re: Is it possible to make alternative macro?
Post by: HSE on November 30, 2021, 03:09:58 AM
No problem, I think.

See Hutch's macros in masm64.

More powerful, and complex, are Mabdelouabad macros.
Title: Re: Is it possible to make alternative macro?
Post by: jj2007 on November 30, 2021, 07:21:00 AM
include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

.code

start:
  mov eax, 3
  .if eax & 4
inkey "bit 2 is set"
  .else
inkey "bit 2 is not set"
  .endif
exit

end start
Title: Re: Is it possible to make alternative macro?
Post by: HSE on November 30, 2021, 08:25:06 AM
Here I'm using "cmp", but you can modify macros and use "test". Hutch's macros are more clear but you can make only 20 levels  :biggrin:, with this You can use any number of levels.

This are simplified macros:__if_ttt_n0 = 0
__if_ttt_level = 0

__if_ttt_resuelve macro m1, a1, a2
% &m1
% cmp &a1, 0
ifnb <&a2>
jg @CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,%__if_ttt_n1)
else
je @CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,%__if_ttt_n1)
endif
endm

@if macro m1, a1, a2
if __if_ttt_level eq 0
__if_ttt_n0 = __if_ttt_n0 + 1
endif
__if_ttt_level = __if_ttt_level + 1
__if_ttt_n1 = 0
__if_ttt_resuelve <&m1>, &a1, &a2
endm

@elseif macro m1, a1, a2
jmp @CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level)
@CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,%__if_ttt_n1,<:>)
;% &m1

__if_ttt_n1 = __if_ttt_n1 + 1
__if_ttt_resuelve <&m1>,&a1, &a2

endm

@else macro
jmp @CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level)
@CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,%__if_ttt_n1,<:>)
__if_ttt_n1 = __if_ttt_n1 + 1
endm

    __if_ttt_setEnd macro
        @CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,<:>)
    endm
@endif macro
@CatStr(__if_ttt_,%__if_ttt_n0,<_>,%__if_ttt_level,%__if_ttt_n1,<:>)
__if_ttt_setEnd
if __if_ttt_level gt 0
__if_ttt_level = __if_ttt_level - 1
endif
endm


Must be used:        mov eax, clipUnion
        and eax, POLYGON_CLIP_RIGHT
        ;int 3
            @if <>, eax
                     ***************
    cond1 macro
           DbgText "test 2"
   mov eax, clipUnion
   and eax, POLYGON_CLIP_LEFT
   ;int 3
    endm

            @elseif <cond1>, eax
                    ************************

            cond1 macro
                mov eax, POLYGON_CLIP_RIGHT
            or eax, POLYGON_CLIP_LEFT
            and eax, clipSum 
            endm
            @elseif <cond1>, eax, 0
                   **************     

           @else
                ************
            @endif





A more complex thing using Mabdelouahab's macros is in  if-elseif Mab's macros for floating comparisons (http://masm32.com/board/index.php?topic=8790.msg95887#msg95887)

PD: just in case. The smile about 20 levels is that is a lot  :biggrin: I think I used at most 6 levels.
Title: Re: Is it possible to make alternative macro?
Post by: daydreamer on November 30, 2021, 12:52:04 PM
thanks JJ,Hector :thumbsup:
polygonclip code,why not SSE solution?
its similar solution to packed compare which returns either FFFF or zero which you can shift and use AND,OR,XOR to check .IF variable>left and variable<right
Title: Re: Is it possible to make alternative macro?
Post by: HSE on November 30, 2021, 01:23:48 PM
 :biggrin: Just a translation from C++.
Title: Re: Is it possible to make alternative macro?
Post by: daydreamer on November 30, 2021, 08:43:04 PM
Quote from: HSE on November 30, 2021, 01:23:48 PM
:biggrin: Just a translation from C++.
That's the usual approach to learn some new algo
First you research and find some hll example, first get it working right
After that optimize when you understand how it works

Title: Re: Is it possible to make alternative macro?
Post by: Vortex on December 01, 2021, 03:13:53 AM
Quote from: daydreamer on November 30, 2021, 01:11:01 AM
Alternative macro similar to. If. Else.endif
But when using test different bits?

Why would you need alternative macros?
Title: Re: Is it possible to make alternative macro?
Post by: daydreamer on December 12, 2021, 09:03:11 AM
Quote from: Vortex on December 01, 2021, 03:13:53 AM
Quote from: daydreamer on November 30, 2021, 01:11:01 AM
Alternative macro similar to. If. Else.endif
But when using test different bits?

Why would you need alternative macros?
thanks to JJ I dont need bit testing macro :thumbsup: