Anderson Green
Anderson Green

Reputation: 31810

If-else macro in MASM

In MASM, is it possible to create an if...ekse macro (similar to those found in high-level programming languages)? I haven't yet found any kind of if-else statement macro for MASM, but I think a macro for this purpose would be very useful.

It would be useful if I could find a macro to make it easier to write a complicated series of if-statements in masm, as shown here:

;jump to each case here
    checkCase1:
    cmp theVariable, 5;
    jne case1; 

    checkCase2:
    cmp theVariable, var2;
    jne case2;

    jmp defaultCase; do this if no other statement is true
;each of the cases are handled here

    case1:
    ;handle case 1
    jmp checkCase2; //check whether case 2 is true

    case2:
    handle case 2
    jmp endOfStatement;
    defaultCase:
        ;this is the default case
endOfStatement:
;this is the end of the statement

Upvotes: 1

Views: 11292

Answers (2)

BJury
BJury

Reputation: 2604

Yes, as below.

if preservebx eq 1
    push bx
else
    mov byte ptr [rdx], bl
endif

The somewhat terrible reference is here: https://learn.microsoft.com/en-us/cpp/assembler/masm/directives-reference?view=msvc-170

Upvotes: 0

Gunner
Gunner

Reputation: 5884

Nobody reads the manual anymore??? Assembly has been around for YEARS, MASM has been out for YEARS!!! Tons of samples and documentation!!!

For example:

.if eax == 1

.elseif eax !=10

.elseif eax >= 11

.else

.endif

MASM32 contains a case macro...

Upvotes: 7

Related Questions