flat assembler
Message board for the users of flat assembler.

Index > Main > How a multiplatform code works?

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
I'd like to know how my programs may run in Windows and Linux (for example).

Lets figure out a simple program which show a MessageBox.

How my code must be to show it in both platforms?

_________________
Sorry if bad english.
Post 27 Jan 2010, 15:07
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
your code will be layered.
the application layer
and the interface layer
interface layer is the one connected to OS.
Post 27 Jan 2010, 15:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Teehee: You have to know the system/OS GUI interface to be able to show things like MessageBox.

There are some cross-platform libraries that attempt to make this easier, e.g. QT is one such library. There are others also.
Post 27 Jan 2010, 15:41
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
its something like:
Code:
push 0
push 0
push text
push 0
call [MessageBox]

MessageBox:
  if (win)
    invoke Messagebox,etc
  else
    invoke LinuxMB,etc
ret
    

?
Post 27 Jan 2010, 16:05
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
That's the Windows API, which would work under Linux only if Wine is installed.
Post 27 Jan 2010, 17:13
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Borsuc, I think you missed the conditional assembly part (although he should have used "call" without square brackets).
Post 27 Jan 2010, 17:28
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Teehee: conditional assembly would work, but it'd be a maintenance nightmare - you'll need to write an OS abstraction layer if you plan on getting anything done, and only use that abstraction layer from your client code. And then you have the wonderful task of implementing the abstraction layer for each OS...

If you only need simple stuff (console mode apps, file handling, memory) then it's a sort of manageable task, but add in GUI and support for more complex features... well, good luck.
Post 28 Jan 2010, 00:05
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Teehee wrote:
I'd like to know how my programs may run in Windows and Linux (for example).


Impossible. You can mix Win32 with DOS, but NOT Win32 with Linux: Linux requires "?ELF" Sigi, while Windows needs "MZ" - one file can't have both.
Post 28 Jan 2010, 06:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Actually, since you mentioned Win32, you could write a COM with embedded ELF and then, when the binary is running under ntvdm you would construct a temporary PE file at run-time and then execute it and when running on Linux you would do nothing as it is already executing in 32-bit mode (I think someone in this forum did that or posted something about it long ago).
Post 28 Jan 2010, 08:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
LocoDelAssembly wrote:
Actually, since you mentioned Win32, you could write a COM ..., when the binary is running under ntvdm you would construct a temporary PE file at run-time and then execute it ...
Can a DOS program tell Windows to run a PE file? What is the DOS call for that function?
Post 28 Jan 2010, 08:25
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution,

Yes, it can (plain int 21/ax 4B00). DOSONLY from CONFIG.NT (or PIF advanced setting for Win9x) selects whether MZ or PE will be run.
Post 28 Jan 2010, 11:02
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
@DOS386

I think he meant it to be assembled as one or the other depending on the target system. Something like:
Code:
SYSTEM equ 0  ; 0 = ELF (don't forget to link the
            ; object file with the appropriate libs)
;SYSTEM equ 1   ; 1 = PE


match = 0,SYSTEM
{
format ELF
public main
}
match = 1,SYSTEM
{
format PE GUI 4.0
entry main
}


main:
       ret
    
Post 28 Jan 2010, 12:07
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
@Teehee

The best way IMO is, like revolution said, to use cross-platform toolkits like GTK+ and Qt, along with code like the above for conditional inclusion of "headers".

Other than that, you can try edfed's method, IOW something like fasm, with system-independent code inside .inc files (e.g. %FASMDIR%/SOURCE/*) and system-dependent UI and API inside the main .asm file of every platform (e.g. %FASMDIR%/SOURCE/LIBC/FASM.ASM, %FASMDIR%/SOURCE/DOS/FASM.ASM).
Post 28 Jan 2010, 12:18
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
LocoDelAssembly wrote:
Borsuc, I think you missed the conditional assembly part (although he should have used "call" without square brackets).
But the parameters aren't the same... plus most functions have no equivalent, since the GUI APIs are different.

_________________
Previously known as The_Grey_Beast
Post 28 Jan 2010, 17:33
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Finally, I found it: http://board.flatassembler.net/topic.php?t=5625

The part that can run in DOS/Linux is in this link posted by rugxulo in that thread: http://www.deater.net/weave/vmwprod/asm/
Post 31 Jan 2010, 03:29
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 GitHub, YouTube, Twitter.

Website powered by rwasa.