It is currently Wed Jan 20, 2021 4:17 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: ASM macros Tips ... or tricks...
PostPosted: Fri Aug 15, 2014 4:01 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
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.

Code:
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])


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM macros Tips ... or tricks...
PostPosted: Fri Aug 15, 2014 5:10 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1359
Location: Germany, Glienicke
These Macros are strange.
Why not only:
Code:
CompilerIf SizeOf(Integer) = SizeOf(Long)
   Macro rax : eax : EndMacro
   Macro rbx : ebx : EndMacro
   Macro rcx : ecx : EndMacro
   Macro rdx : edx : EndMacro
   Macro rsi : esi : EndMacro
   Macro rdi : edi : EndMacro
   ; ...
CompilerEndIf

Define *Buffer.Long = AllocateStructure(Long)

EnableASM
   mov rax, *Buffer
   mov [rax], dword 123
DisableASM

Debug *Buffer\l

In this case I can use my normal x64-ASM code.

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM macros Tips ... or tricks...
PostPosted: Sat Aug 16, 2014 1:17 am 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
When I tried that using the "!" to denote asm, that style of macro did not work. I did not try it with EnableAsm.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye