I want to create macros that doesn't include jmp if it is done to the next command. I tryed this macro, but fasm tells me that code cannot be generated if I call it like jmp @f / @@:.



macro jmp lab
{
local ..addr, ..lab
label ..addr
label ..lab at lab
virtual at 0
jmp ..lab-..addr
load ..opcode word from 0
end virtual
if ..opcode<>0ebh
jmp lab
end if
}
Posted on 2003-02-07 19:15:47 by wanderer
The problem is because after you remove instruction with EB-00 opcode the label that is defined just after this instruction will move two bytes down and in next pass (FASM does it because of changed value of label that was used earlier) that instruction will be assembled to EB-FE, because this time label points to the place of that instruction, some this time instruction is assembled and label moves two bytes up again and so it leads to unresolvable loop. I don't know if there's any simple solution to make macro of such functionality, if I invent something, I'll let you know.
Posted on 2003-02-08 07:08:38 by Tomasz Grysztar
All right, I've got the solution:


macro jmp lab
{
local ..ip,..opcode,..removed
virtual
..ip: jmp lab
load ..opcode word from ..ip
end virtual
if (..opcode = 0EBh & ~ ..removed) | (..opcode = 0FEEBh & ..removed)
..removed = 1
else
jmp lab
..removed = 0
end if
}
Posted on 2003-02-08 07:14:02 by Tomasz Grysztar
Thank you very much, Privalov.
Posted on 2003-02-09 07:04:06 by wanderer