Question:
Does assembly lanuage of the same architecture run on different operating systems?
Owemecent
2014-02-07 18:44:24 UTC
I recently made a small program in C++ that does algebraic math equations and compiled it in G++ on linux. I want to give it to my friends so they can use it in school. The problem is that they use windows and G++ only compiles the source into a linux binary. So I had the idea that I could convert the C++ source into assembly source and just run it from the command prompt. It is possible?
Four answers:
Andrew S
2014-02-07 20:25:08 UTC
It IS possible in very limited circumstances. The actual machine code is the same on both systems but any calls to operating system services will be different between the two platforms. Since any useful program needs to deal with the operating system at some point (input, output or even to terminate) what you can do in a portable manner between the two systems is very limited.



On the other hand you can certainly code assembly functions that can be used on either platform, it just needs to be within a wider program. The biggest limitation then tends to be there is no way to allocate memory but if a function doesn't need to do that, or it is arranged in advance that a known function will be supplied by the programs that it can call, then you can do quite a lot of intensive processing in assembler and not lose portability.



However, that doesn't solve your problem. If this is a simple command line app hopefully the operating system dependencies are few to non-existent. It shouldn't be too difficult to simply recompile on Windows so that the resulting executable knows how to make the correct operating system calls.
?
2014-02-08 05:06:04 UTC
Just to reiterate husoki's answer to further clarify Andres S's answer, you cannot create an executable binary that will be cross-platform (i.e. assembly language). Assuming the same architecture, the assembler should construct byte code that can execute the same ISA instructions. However, EVERY executable contains OS specific code. Particularly in the execution. The program to be executed MUST go through the OS. It must request a page of memory from the OS. So even without things like I/O which will be OS-specific even the launching the program needs to call OS functions.



Like Andrew S points out, you could probably create subroutines which only call ISA instructions (specific to the architecture) and rely on the ABI (how the program will run--which, at least, for things like C, is uniform between different OS's).



Still, it's best to rely on a compiler to generate the binary.
Jonathan
2014-02-08 07:05:08 UTC
You already have reasons why you can't. But here are some thoughts about how you might:



Wine 1.6 will let you run a fair number of Windows applications on Linux. Given your application, it would probably work fine if you write it for Windows and then use Wine on your end to run it. Obviously, that makes it easy for your friends because they are running Windows.



The mono project works under Linux, as well, and provides a limited subset of .NET. .NET uses a low level language (MSIL/CIL) and VB.NET, C#, and F# from Microsoft all target .NET. If you write an application that targets the mono subset of .NET (somehow... and you'd need to research it), then it should theoretically run fine on Windows. .NET/mono read up the same executable formats, do "just in time" compilation of MSIL into machine code, and provide a base set of .NET style classes and other services. Might be another way to go.



Java comes to mind, of course.



Take a look at Codeweaver's Crossover 13, as well.



And I think there probably are a number of software compiler/interpreter tool vendors creating tools that will cross target a variety of operating systems. I know for certain some of them target IOS/Android/Windows.
husoski
2014-02-08 02:52:01 UTC
No, you'd have to compile a Windows version for them to use it. Even with assembler, the binary executable program formats are different on different OSes, and the system calls necessary to perform I/O, manage memory and program execution are also unique to each OS.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...