Hi, this should be an easy question, but I can't seem to work it out. I have a macro in which I'm trying to pass a numeric value to be converted into a register name, i.e.
MyMacro MACRO RegNumber
mov r&RegNumber, 1
ENDM
TestProc PROC
...
MyMacro 8
That works fine, creating the instruction: mov r8, 1. But it fails when I need to calculate the name off an expression, it fails, i.e:
MyMacro MACRO RegNumber
mov r&(RegNumber+7), 1
ENDM
I've gotten it to work with a nested-macro approach (see below), but this is cumbersome. There must be a way to do it within a single step. Thanks for any help.
; Pre-expand expression before calling main macro
MyMacro1 MACRO RegNumber
MyMacro2 %(RegNumber+7)
ENDM
MyMacro2 MACRO NewRegNumber
mov r&NewRegNumber
ENDM
include \Masm32\MasmBasic\Res\JBasic.inc
MyMacro MACRO RegNumber
mov @CatStr(<r>, %(RegNumber+7)), 11111 ; fixed value
ENDM
Assign MACRO RegNumber, value
mov @CatStr(<r>, %(RegNumber+7)), value
ENDM
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
MyMacro 2
Print Str$("The value is %i\n", r9)
Assign 1, 12345
Print Str$("The value is %i\n", r8)
EndOfCode
Output:
This program was assembled with ml64 in 64-bit format.
The value is 11111
The value is 12345
Works perfectly, thanks!