flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Converting macro from masm

Author
Thread Post new topic Reply to topic
prana



Joined: 28 Aug 2003
Posts: 51
prana 03 Oct 2003, 17:45
I've a pair of macros like the following written for masm:

return macro
___ret =$
ret
endm

rz macro
if $-___ret gt 126
jnz $+3
___ret = $
ret
else
jz ___ret
endif
endm


How this can be recoded for fasm, without using any .if macro?
Also if I use it, how the listing should look like?

Thanks for your help.
Post 03 Oct 2003, 17:45
View user's profile Send private message Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 04 Oct 2003, 06:16
I was testing it like this:
____________________________________

macro return
{
___ret =$
ret
}

macro rz
{ push ax
mov al,126
cmp al,($-___ret)
jnz $+3
___ret =$
ret
jz ___ret
}

org 100h

main:
mov al,0
cmp al,0
rz
__________________________________________________


However, running this program causes an NTVDM error.

Any help?
Post 04 Oct 2003, 06:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 04 Oct 2003, 10:20
You can compare two absolute values at the assembly time, like "if $-__ret>126", and the run-time comparision makes completely no sense for such kind of macro. However, even the original macro for masm seems a bit wrong for me, but I'm not sure how masm will react for such ambiguous situations, when you try to check value of some constant that was not defined yet in a way to determine whether define it or not (fasm won't let you do such things, because they are creating a mess). The correct version for fasm should look like:
Code:
macro return
{
 ___ret = $
 ret
}

macro rz
{
 if defined ___ret
  if $-___ret > 126
   jnz $+3
   ___ret = $
   ret
  else
   jz ___ret
  end if
 else
  jnz $+3
  ___ret = $
  ret
 end if
}    
Post 04 Oct 2003, 10:20
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 04 Oct 2003, 20:16
yes, got it!
Thanks boss! However I missed the last "ret " in my previous posting:
It was like:


______

.......
.....
org 100h

main:
mov al,0
cmp al,0
rz
ret

_____________

Thanks! Very Happy
Post 04 Oct 2003, 20:16
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.