flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] 'invalid instruction' problem

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
To learn fasmg, I try to re-create x86 architecture

Code:
macro x86.parse_operand ns*, operand*
  match =byte? value, operand
    ns.size = X86_OPERAND_SIZE_BYTE
    x86.get_operand_type ns, value
  else match =word? value, operand
    ns.size = X86_OPERAND_SIZE_WORD
    x86.get_operand_type ns, value
  else match =dword? value, operand
    ns.size = X86_OPERAND_SIZE_DWORD
    x86.get_operand_type ns, value
  else
    ns.size = X86_OPERAND_SIZE_UNDEFINED
    x86.get_operand_type ns, operand
  end match
end macro

macro x86.get_operand_type ns*, value*
  match [addr], value
    ns.type = 'mem'
    ns.value = +addr
  else match segment:offset, value
    ns.type = 'farptr'
    ns.segment = +segment
    ns.value = +offset
    match [addr], offset
      ns.type = 'mem'
      ns.value = +addr
    end match
  else
    ns.type = 'imm'
    ns.value = +value        ; <<<<<<<<<<<<<<<<<<<
    if ns.value eq ns.value element 1
      if (ns.value metadata 1) metadata 1 relativeto x86.reg
        ns.type = 'reg'
      else if ns.value metadata 1 relativeto x86.sreg
        ns.type = 'sreg'
      end if
    end if
  end match
end macro

macro add? dest*, src*
  ;x86.parse_operand _operand1_, dest
  x86.parse_operand _operand2_, src

end macro
    

Marked string throws "Error: illegal instruction" for immediate operand:
Code:
add bx, 1    
. It's not allowed to use variables with the same name (If I change "ns.value" to "ns.imm" orr anything else in the final ELSE clause, then code compiles without errors). But why? 'value' variables, as I see them, are in different namespaces. Could anyone clarify this behavior please?
Post 29 Apr 2016, 21:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7750
Location: Kraków, Poland
Tomasz Grysztar
"." is a special character in fasm g, so when you have macro parameter named "value", it gets replaced in the expression "ns.value". It should not have been unexpected - since in "ns.value" the "ns" parameter is replaced (and the macro uses this), so is "value".
Post 30 Apr 2016, 06:02
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.