A note on Flat Assembler's macro capabilities

One of the huge advantages of Flat Assemblers over other assemblers for the Intel platform is its macro engine. In addition to being able to perform its original task--substituting macro instructions with their definitions--it is able to perform relatively complex computations, and I would dare to call it an additional programming language. The preceding examples only utilize a tiny fraction of what FASM's macro processor is capable of. While we only used a set of if clauses and a variable, we may, in necessary cases, use loops (with while or repeat statements). For example, imagine a string of characters that you want to keep encrypted:

my_string  db 'This string will be encrypted',0x0d, 0x0a, 0x00
my_string_len = $ - my_string

Here, my_string_len is the length of the string.

$ is a special symbol denoting the current address. Thus, $-my_string means the current address minus the address of my_string, which is the length of the string.

A simplistic XOR encryption may be applied with just a four-line macro:

repeat my_string_len
load b byte from my_string + % - 1
store byte b xor 0x5a at my_string + % - 1
end repeat

The % symbol here denotes the current iteration and the -1 value is needed because the count of iterations starts at 1.

This is just a short and primitive example of what the macro engine of FASM is able to do, and there is a lot more. However, this book, though it uses FASM as a primary assembler, is dedicated to Intel Assembly language rather than to specific dialect, so this additional information goes beyond its scope. I strongly recommend that you refer to the FASM documentation available at http://flatassembler.net.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset