How to build a number in fasm at the stage of compilation? For other actions with numbers, for example, a bit shift can be written like this: mov ax, 10 shl constant , but the code mov ax, 10 pow constant , is not compiled.

  • As far as I understand, there is no way. Here in this table there is no such command as exponentiation. - Zealint
  • @Zealint is understandable, but maybe you can write some macro? - Im ieee

1 answer 1

Wrote the macro pow , it turns out a bit crutch, but it works:

 ; Параметры макроса: основание, показатель степени (неотрицательное целое число), переменная-приёмник результата macro pow x, y, result { result = 1 rept y \{ result = result * x \} } pow 10, 5, a ; возводим 10 в степень 5, результат кладём в переменную a dd a ; должно получиться 100000 dd 100000 ; эталонное значение для сравнения 

Result of compilation in hex form:

 A0 86 01 00 A0 86 01 00 

We see 0186A0h (100,000 in the decimal system) two times, as required.

  • Thanks, the code is really working. And you can make the macro not save the value in a variable, but directly substitute the value in the assembler instruction - as in my example? - Im ieee
  • @Imieee, it just won't work. In the win32ax.inc include file, it is possible to, for example, invoke macro from another invoke and other macros declared there, but for mov , for example, this is not implemented. The macro allow_nesting there takes up 62 lines. - insolor
  • If it is needed only in mov , then mov will have to be redefined, if there are any other db , dw , dd , then they must also be redefined to support the macro call from the parameters. Out of the box itself will not work. - insolor
  • It is necessary not only in mov . A macro of this kind can be implemented: p mov ax, 10 pow 5 ? That is, the macro p is called, which for all arguments replaces [0-9]+ pow [0-9]+ with exponentiation. The rest of the arguments simply displays. - Im ieee
  • @Imieee, in theory, you can, but I'm not so strong in macros) You can try to ask on board.flatassmebler.net, I think, they will tell you there. - insolor