I need to do this on a macro ... any tutorial, code, idea appreciated ! :D: if sw_command == 0 sub variable1,variable2 endif Thx
...or did you only want to generate the sub instruction when when sw_command is zero?
yourMacro MACRO sw_command, variable1, variable2 LOCAL XyourMacro cmp sw_command, 0 jne XyourMacro sub variable1,variable2 XyourMacro: ENDM
The first one seems more useful. :)
yourMacro MACRO sw_command, variable1, variable2 IF (sw_command EQ 0) sub variable1,variable2 ENDIF ENDM
In the first MACRO above, variable1 or variable2 must be a register. You could make it more general with the following...
...or pass it a register to trash. There are many ways to do it. :) When I use MACROs I try to not change anything not passed to them. This makes reading the code, and making changes in the future easier. For example, if EAX was destroyed in the above MACRO, how would we know that in six months? Or, what if we created our own psuedo language with MACROs? The fewer transparent changes that take place within the MACRO the better. The MACRO above still assumes that we have a stack to put four bytes on, but that's not too bad an assumption. :) MACROs are very powerful things, that can save you as much (or more) coding than sub-routines! I've got in the habit of coding MACROs like this:
yourMacro MACRO sw_command, variable1, variable2 LOCAL XyourMacro cmp sw_command, 0 jne XyourMacro push eax mov eax, variable1 sub variable2, eax pop eax XyourMacro: ENDM
It'd be great to here ideas from others on techniques that they've developed.
yourMacro MACRO sw_command, variable1, variable2, xREG LOCAL XyourMacro cmp sw_command, 0 jne XyourMacro mov xREG, variable1 sub variable2, xREG XyourMacro: ENDM