Issues using a local label in a macro in MASM
Asked Answered
O

1

6

I'm to write a macro that takes E,NE,A,B... as a parameter and a single command i.e mov eax,ebx which would execute if the condition set by a preceding cmp operation is true.

An example call would look like.

cmp bx,20
mDoIf E,<call Dumpregs>

The issue I'm running into is that when I attempt to compile with the below definition I get one of two errors. With the LOCAL definition I get an Undefined Symbol Error: ??0000. When I remove the LOCAL definition I get an error: jump destination must specify a label.

mDoIf MACRO op, command
    LOCAL true
    J&op true
    exitm
    true: 
        command
        exitm

endm

Any help would be appreciated. Thank you.

Opportune answered 12/12, 2013 at 3:39 Comment(2)
Try left-margin aligning the label "true:".Satisfied
Sorry no dice. I suppose I should give some information on what I'm using to compile stuff. I'm using Visual Studio 2012 professional with the irvine32.lib from Kip Irvine's Assembly Langauge for x86 processors 6th edition. Having labels indented has not caused me grief in the past, though I did try your suggestion to see if it would work.Opportune
E
7

Try this:

mDoIf MACRO op, command
    LOCAL L1, L2

    J&op    short L1
    jmp     short L2

L1: 
    call command
L2:
    exitm
endm

.code
start:
    mov     eax, 1
    cmp     eax, 2
    mDoIf l, DumpRegs

    invoke  ExitProcess, 0
end start
Escargot answered 12/12, 2013 at 5:13 Comment(3)
Thank you very much. NO WHERE in the chapter on macro's did they mention using short. Could you break down why this works as opposed to why mine didn't? Also I just tested it and as long as you include the second argument in <> and it's a valid assembly instruction you can just have L1: commandOpportune
it should work without short. your issue was the misplaced exitm. if that is before your labels, the preprocessor will not "see" them when the macro gets expanded. one of the many uses of macros is to help cut down on typing, why add extra characters to the macro params?Escargot
Agreed, but we were to accept any valid assembly instruction not just calls. i.e I should be able to execute mov eax, ebx if passed in as a param.Opportune

© 2022 - 2024 — McMap. All rights reserved.