ASM macros Tips ... or tricks...
Posted: Fri Aug 15, 2014 4:01 pm
Here is a set of macros that can remove the conditional compilation of most instructions between x86 and x64. There is no provision for instructions that are not 1:1, but that could be dealt with too, if there are not many.
The first macro is required to allow the substitution of the register names. Otherwise the code is handled directly as asm code, and substitutions are not made. The second conditional set allows the eight registers to be defined without the conditional wrap, so there are 10 macros instead of 16.
The first macro is required to allow the substitution of the register names. Otherwise the code is handled directly as asm code, and substitutions are not made. The second conditional set allows the eight registers to be defined without the conditional wrap, so there are 10 macros instead of 16.
Code: Select all
Macro asm(instruction, arg1, arg2)
!instruction arg1, arg2
EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
Macro eORr
r
EndMacro
CompilerElse
Macro eORr
e
EndMacro
CompilerEndIf
Macro xax
#eORr#ax
EndMacro
Macro Xbx
#eORr#bx
EndMacro
Macro Xcx
#eORr#cx
EndMacro
Macro Xdx
#eORr#dx
EndMacro
Macro Xbp
#eORr#bp
EndMacro
Macro Xsp
#eORr#sp
EndMacro
Macro Xsi
#eORr#SI
EndMacro
Macro Xdi
#eORr#di
EndMacro
; Sample:
asm(MOV, xdx, [p.p_MemoryBuffer])
asm(MOV, xax, [p.p_Character])