Переменные в макросах fasm

Discussion in 'WASM.BEGINNERS' started by HH9, Dec 25, 2009.

  1. HH9

    HH9 New Member

    Blog Posts:
    0
    Joined:
    Nov 28, 2007
    Messages:
    72
    Всем привет.
    Подскажите, как на макросах фасма можно сделать следующее.
    В зависимости от значения n, cmd должна принимать значение mov или xor.
    Теоретически код должен работать, но интерпретатор игнорирует условия, и подставляет всегда последнее значение.
    Код:
    Code (Text):
    1. macro maken n {
    2. local cmd
    3.  
    4.       if n=1
    5.       cmd equ mov
    6.       end if
    7.       if n=2
    8.       cmd equ xor
    9.       end if
    10.  
    11.       cmd esi, eax
    12. }
    Каким образом можно заставить его работать правильно?
     
  2. litrovith

    litrovith Member

    Blog Posts:
    0
    Joined:
    Jun 20, 2007
    Messages:
    509
    Code (Text):
    1.   macro maken n
    2. {     if n=1
    3.       mov esi, eax
    4.       else if n=2
    5.       xor esi, eax
    6.       end if }
    7.  
    8.   macro maken2 n
    9. {     if n=1
    10.       cmd=8Bh
    11.       else if n=2
    12.       cmd=33h
    13.       end if
    14.       db cmd, 0F0h }
     
  3. HH9

    HH9 New Member

    Blog Posts:
    0
    Joined:
    Nov 28, 2007
    Messages:
    72
    если бы все было так просто...
    я хотел сделать подобие полиморфного генератора
    Посмотрел документацию, вот что в ней написано:
    Code (Text):
    1. I'm trying to conditionally define some constant with equ directive by
    2. putting it in the if block, but it seems that even when this condition is
    3. false, the constant gets defined. Why?
    4.  
    5. That's because all symbolic constants and macroinstruction (that means
    6. every symbol you define with equ, macro,
    7. or struc directive) are processed at the preprocessor stage,
    8. while directives like if or repeat are processed
    9. at assembly stage, when all macroinstructions and symbolic constants have already been replaced with corresponding
    10. values (generally structures which you have to end with the end directive followed
    11. by the name of structure are processed at assembly stage). On the other hand, the numerical constants
    12. (which you define with = symbol) are of the same kind as labels,
    13. and therefore are processed at assembly stage, so you can define and use them conditionally.
    Видимо придется писать свой препроцессор... а жаль, у фасма макросы вполне на уровне.
     
  4. litrovith

    litrovith Member

    Blog Posts:
    0
    Joined:
    Jun 20, 2007
    Messages:
    509
    HH9, я тож думал написать на макросах ). стукни в пм.
     
  5. Sol_Ksacap

    Sol_Ksacap Миша

    Blog Posts:
    0
    Joined:
    Mar 6, 2008
    Messages:
    623
    Поскольку макросы раскрываются во время препроцессинга, то и использовать в данном случае нужно директивы времени препроцессинга (а "if" – директива времени компиляции).
    Code (Text):
    1. macro maken n
    2. {
    3.     match =1,n
    4.     \{ xor eax, eax \}
    5.     match =2,n
    6.     \{ mov eax, 0 \}
    7. }
     
  6. HH9

    HH9 New Member

    Blog Posts:
    0
    Joined:
    Nov 28, 2007
    Messages:
    72
    Спасибо, работает.