flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasm g] how do I concatenate strings

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
How do I concatenate multiple strings into one?
Code:
macro cpu? type
  include 'arch/'#`type#'.inc'
end macro

cpu 8086    

doesn't seem to be working in fasm g
Post 20 Apr 2016, 22:33
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2942
Location: vpcmipstrm
bitRAKE
I don't know if this is the intended way?
Code:
macro cpu? type*
  eval 'include "arch/',`type,'.inc"'
end macro

cpu 8086    
Yet, it seems to work. Very Happy
Post 21 Apr 2016, 03:38
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
I'm so dumb Sad I tried eval, but used it improperly. Thanks a lot!
Post 21 Apr 2016, 07:05
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
bitRAKE: good idea! It is a nice solution thanks to its simplicity. It is much nicer than the one I would propose:
Code:
macro cpu? type
  local path
  virtual at 0
    db 'arch/',`type,'.inc'
    load path : $ from 0
  end virtual
  include path
end macro 

cpu 8086    
The direct calculation of concatenation is also possible, though the absence of special operators for string manipulation makes it very tedious:
Code:
struc concat? first*,rest*&
        . = string first
        iterate s, rest
                local str
                str = s
                . = string . + str shl (((bsr . - 1) shr 3 + 1) shl 3)
        end iterate
end struc

macro cpu? type
  local path
  path concat 'arch/',`type,'.inc'
  include path
end macro 

cpu 8086    
When working on this example I discovered another hidden bug in the fasm g engine. Thank you! Wink


Last edited by Tomasz Grysztar on 21 Apr 2016, 08:53; edited 1 time in total
Post 21 Apr 2016, 08:22
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
I have uploaded the bugfix. Now that macro works correctly also in this form:
Code:
struc concat? first*,rest*&
        . = string first
        iterate s, rest
                . = string . + (s) shl (((bsr . - 1) shr 3 + 1) shl 3)
        end iterate
end struc    
Before I fixed the bug, it did not work because the iteration parameter messed up the recognition context for the subsequent "." symbol.
Post 21 Apr 2016, 08:47
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.