Hi
I want to share my new supermacro ideas: What macro doing? It inserts some part of the code as many times as we use it. Let's stop it. We can insert some part as function just once and call it as many times as we need.
macro .function name
{
if name = 0
jmp once#name
name = $
push rbp
}
macro .endf name
{
pop rbp
ret 0
once#name:
end if
if ~ name = 0
call name
end if
}
Example of declaring:
ConvertRegToASCII = 0
macro Convert key,Dest_any,Source_any
{
if key eq RegToASCII
mov rdi,Dest_any
if Source_any eq rax
else
mov rax,Source_any
end if
.function ConvertRegToASCII
mov rbx,10
xor rcx,rcx
@@:
xor rdx,rdx
div rbx
add dl,30h
push rdx
inc rcx
cmp rax,0
jne @B
@@:
pop rdx
mov BYTE[rdi],dl
inc rdi
dec rcx
cmp rcx,0
jne @B
mov BYTE[rdi],0
.endf ConvertRegToASCII
end if
}
And now if you use your macro more than once it will NOT duplicate the code.
Convert RegToASCII,txtMonitor1,r10
Convert RegToASCII,txtMonitor2,r11
Convert RegToASCII,txtMonitor3,r12
Convert RegToASCII,txtMonitor4,r13
You also may call your newly created function as usually do by
call ConvertRegToASCII
push/pop rbp and
ret 0 required for compatibility with
proc