flat assembler
Message board for the users of flat assembler.

Index > Main > multiplatform code

Author
Thread Post new topic Reply to topic
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz
I am writing some multiplatform code. It runs on both linux and windows since both OS use cdecl calling convention on x86. Problem is - format is specified in source file. Having copy of exactly same code with only first line specifying format (MS COFF / ELF) different is not optimal. Command line parameters of assembler are scarce. I was wondering what would be the right way deal with this situation here?
Post 15 Jul 2015, 15:51
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
roxaz
You just create a main file for each individual platform and then use the include directive to include the platform independent code located in separate files. Effectively this creates a differentiation of the target platform by altering the command line: fasm lin_project.asm vs. fasm win_project.asm .

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Jul 2015, 17:19
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
I usually use the two files method l_inc mentioned, as it allows greater flexibility/capability where platform specific differences are required, but you can also have two different common headers that you reference using environment variables. This works nicely for native platform assembly but is more annoying for cross platform assembly, since you'd have to toggle the environment variable.
e.g.
<path>/common/win64/common.fash (format PE64 GUI)
<path>/common/lin64/common.fash (format ELF64 executable 3)
Set COMMON to the appropriate <path>/common/<platform> and then:
Code:
include '%COMMON%/common.fash'
; YOUR CODE HERE    
Post 15 Jul 2015, 18:04
View user's profile Send private message Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable
The general wisdom today is to create multi platform programs. Just remember that you don't need to do this, only large commercial software developers really need to make cross platform programs (and they don't want to do that, they just need to, if you personally can avoid it, you should avoid it)

Do not be afraid to write programs that only works for one specific type of platform. Idiots try to make their program work for any platform, and pioneers try to drag people over to using the platform they prefer.

Do not be afraid to try to be a pioneer, when you create a program for one specific type of platform, you increase the probability that a user will switch to that platform, permanently.

Just remember that your goal is not to make everything work for any platform, your ultimate goal is to make one platform more attractive than the next. THATS wisdom. So do not be afraid to disappoint any users out there. Try to tempt them to switch platform.

The reason some people prefer one platform over the other is because some features work better on one platform than the other. What you should do, is to prefer the one that works better and encourage users to switch to the one you think is better. The term 'cross platform apps' is just a very ugly spell that has been cast upon people, they don't even know why they are doing it.

The general approach is to "satisfy everyone", but the approach should be to invite people to become satisfied, it's not the other way around. It's not about adapting to a thousand different "rats" in the world, it's about killing all the rats, and then buy a very nice big dog that you can pet.
Post 15 Jul 2015, 21:08
View user's profile Send private message Reply with quote
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz
Thanks guys, i totally did not think of env variables and includes. After all its multiple years after i last did any coding with fasm.

@PeExecutable: you are right, not every platform has to work, but main ones has because im working on compiler feature. So goal is to make it at least work on x86/x64/windows/unixes. Luckily this is all covered by basically 3 different platform-dependent sets of code: cdecl and fastcall for x86 is same on both unixes and windows, then we have ms x64 abi and sysv x64 abi. So not much work really. Ofc there is at least arm too on the horizon but thats for later. Wink If you are wondering which compiler here is shameless advertisement: http://nim-lang.org/
Post 16 Jul 2015, 06:31
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.