I have mentioned this trick on a stream when I was working on running fasmg in 64-bit mode, but it is buried in that long and boring recording and perhaps it is worth making it more easily reachable information.
If you happen to have a free register for a part (or even entirety) of your code, you might want to try using it to hold value of something that you normally hold in memory. You might also want to experiment with putting various variables there, to see what gives the best results. If you are using fasmg with its standard x86 macros, there is a very simple trick that allows to do it without having to do something like a search+replace on source text.
With this simple override of "x86.parse_oprerand_value" macro we can enable a new syntax variant for operands:
macro x86.parse_operand_value ns,op
match [&val],op
x86.parse_operand_value ns,val
else
x86.parse_operand_value ns,op
end match
end macro
It allows to use this added syntax:
And then to map a variable to a register, just change its definition like this:
And this then maps instructions like the following into a register access instead of memory: