flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Mapping a variable to a register

Thread Post new topic Reply to topic
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8135
Location: Kraków, Poland
Tomasz Grysztar 26 Oct 2019, 16:49
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
                x86.parse_operand_value ns,op
        end match
end macro     
It allows to use this added syntax:
add [&cl],al ; add cl,al    
And then to map a variable to a register, just change its definition like this:
; var db ?
var equ &cl    
And this then maps instructions like the following into a register access instead of memory:
add [var],al ; add cl,al    
Post 26 Oct 2019, 16:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.