flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [translation help needed] How to convert substr and catstr?

Author
Thread Post new topic Reply to topic
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user 17 Jun 2010, 09:28
Code:
macro   cipher  m
        local   char,low,high,hex8,hex16l,hex16h
        char    substr  <m>,1,1
        low     catstr  char,<l>
        high    catstr  char,<h>
        irp     rch,<al,ah,bl,bh,cl,ch,dl,dh>
         ifidni <m>,<rch>
          sub   m,'0'
          cmp   m,10
          jb    hex8
          sub   m,7
        hex8:
          and   m,0Fh
          exitm
         endif
        endm
        irp     rch,<ax,bx,cx,dx>
         ifidni <m>,<rch>
          sub   m,'00'
          cmp   low,10
          jb    hex16l
          sub   low,7
        hex16l:
          cmp   high,10
          jb    hex16h
          sub   high,7
        hex16h:
          and   m,0F0Fh
          exitm
         endif
        endm
endm    cipher    


I want to port it to FASM, but I'm kind of clueless, FASM's seems to be more complex than TASM Very Happy
Thanks in advance!
Post 17 Jun 2010, 09:28
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 18 Jun 2010, 19:28
flat_user,

Preprocessor can't split symbols (AFAIK), but it can join them:
Code:
macro cipher m {
  irps reg, a b c d \{
    irps half, l h \\{
      match =m, reg\\#half \\\{
      \\\local ..
          sub m, '0'
          cmp m, 10
          jb  ..
          sub m, 7
        ..:
          and m, 0Fh
      \\\}
    \\}
    match =m, reg\#x \\{
      sub m, '00'
      irps half, l h \\\{
      \\\local ..
          cmp reg\\\#half, 10
          jb  ..
          sub reg\\\#half, 7
        ..:
      \\\}
      and m, 0F0Fh
    \\}
  \}
}    
Proper backslashing is crucial.
Post 18 Jun 2010, 19:28
View user's profile Send private message Reply with quote
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user 19 Jun 2010, 02:59
"Proper backslashing is crucial."
What do you mean by that?

Why does it have to be like reg\#x, reg\\\#half, etc.?

So it iterates through all registers and when m is equal to ax, it meanwhile has saved the letter 'a' to then append l and h.

Thanks, I'm gonna test it, just have to read anew about the match-directive, escaping/concatenating and irp..
Post 19 Jun 2010, 02:59
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 19 Jun 2010, 03:28
flat_user,

Number of backslashes before concatenation macro-operator (#) tells at which nesting level it will act. One more, and match directive will try to match macro argument (m) with something like a#x, failing to do that. One less, and you will get literally symbol half (not h or l substituted for it) concatenated with register letter (a, b, c or d), yielding invalid register name like ahalf.
Post 19 Jun 2010, 03:28
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.