Cross-Platform Assembly Language?

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 18394 Views - Last Post: 04 February 2019 - 05:04 AM

#16 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • Posts: 5,898
  • Joined: 03-August 09

Re: Cross-Platform Assembly Language?

Posted 20 June 2011 - 05:07 PM

Quote

If you have to write the same function different ways for each platform then you don't really have a cross platform assembly language

so C/C++ isn't "really" cross platform? you mean to tell me that Qt writes 1 function/method for every system? Qt doesn't use the pre-proc to write different code for different systems? could have had me fooled..
Was This Post Helpful? 0
  • +
  • -

#17 GenHornet18   User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • Posts: 629
  • Joined: 19-October 09

Re: Cross-Platform Assembly Language?

Posted 21 June 2011 - 07:14 AM

View Postishkabible, on 20 June 2011 - 07:07 PM, said:

Quote

If you have to write the same function different ways for each platform then you don't really have a cross platform assembly language

so C/C++ isn't "really" cross platform? you mean to tell me that Qt writes 1 function/method for every system? Qt doesn't use the pre-proc to write different code for different systems? could have had me fooled..


The power of C/C++ cross platform ability doesn't stem from the language itself but from the compiler support. For every new platform to be supported, the application must be recompiled (for things already mentioned, including calling convention, API implementation and binary format). The difference with assembly (and why it's not so easy to reassemble for a new platform) is that assembly code is written specifically based on that platform's characteristics (where the compiled can swap out API calls you would have to do manually in your assembly file.

The assembly language was not designed to be a cross-platform language but as already suggested can be achieved by essentially making two different binaries and mashing them together.

The Portable Executable format for example, includes support for both MS-DOS (via the DOS header), and Windows NT (via the PE header). Two different sections of executable code meant for each specific OS. If done properly then some code would be reusable between them but this stretching the specifications of the format.

You want cross-compatibility include support for both.

Hornet
Was This Post Helpful? 0
  • +
  • -

#18 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • Posts: 5,898
  • Joined: 03-August 09

Re: Cross-Platform Assembly Language?

Posted 24 June 2011 - 12:38 PM

why dose no one seem to understand that cross platform code in C/C++ relays on the pre-proc?

#ifdef WIN
    void foo() {
        //code for windows
    }
#elif LINUX
    void foo() {
        //code for linux
    }
#elif MAC
    void foo() {
        //code for mac
    }
#endif



now however this would be near impossible to do with different architectures. im not trying to say you can write cross-architecture code in assembly, but defiantly cross platform.
Was This Post Helpful? 0
  • +
  • -

#19 GWatt   User is offline

  • member icon

Reputation: 309
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: Cross-Platform Assembly Language?

Posted 24 June 2011 - 02:30 PM

Portability isn't a simple dichotomy. It's a gradient of how many changes do you have to make to get something working on a new system. If you have to make only a few, it's pretty portable. If you have to change a few hundred things and spend a month or so debugging then your application is less portable. With an application coded for assembly you will have to change every single function that interfaces with the operating system or any libraries your program uses. Some of you code will be portable. A large amount of it won't. You've already said the programmer would have to manually handle the ABI issues. The only 'advantage' I've seen is the ability to link against different libraries depending on the system, and I actually don't consider that an advantage. If it becomes the assemblers job to link compiled object file as well as assemble it then you've lost the modularity gained by separating the compiling and linking process.
Was This Post Helpful? 0
  • +
  • -

#20 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • Posts: 5,898
  • Joined: 03-August 09

Re: Cross-Platform Assembly Language?

Posted 26 June 2011 - 02:15 PM

if the library supported a system (e.g. Windows, Mac, ect...) then you shouldn't need to be altered. yes, if we were talking about adopting a new system such as Haiku it would be a ROYAL pain in the ass to change it. you could however write code for say both Linux and Windows with having to change virtually any code if you had a pre-proc.

example, a sleep function

#ifdef WIN32
    ;import Sleep form win32 API
    mySleep:
        pop eax  ;take a 32-bit value off the stack
        push ax  ;push a 16-bit value onto the stack
        jmp Sleep;tail call to sleep
#elif LINUX
    ;import usleep
    mySleep:
        jmp usleep ;argument is already 32-bit, so just tail call usleep
#endif



just simple fast wrapper functions like these could give you nearly all cross platform code. cross architecture would be a fluke im afraid.

This post has been edited by ishkabible: 26 June 2011 - 02:16 PM

Was This Post Helpful? 0
  • +
  • -

#21 pquiring   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-January 19

Re: Cross-Platform Assembly Language?

Posted 30 January 2019 - 09:51 AM

Old post but LLVM offers a cross-platform assembly like language that is CPU agnostic.

http://llvm.org
Was This Post Helpful? 0
  • +
  • -

#22 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: Cross-Platform Assembly Language?

Posted 31 January 2019 - 10:45 PM

A cross platform assembly would not be assembly. I would hide the differences in HW, and assembly is usually used to utilize the HW features.
The OS-differences are usually handled by using libraries like standard C library.
GAS has (almost) the same directives for all architectures, but the instructions are architecture-specific.

Having unabstracted access to the processor helps getting the last tick out of the chip. It's often unacceptable, if you can't figure out the time an instruction takes to execute.

You can view C as a high level portable assembly (although it still has the "taste" of PDP processors).

And even Arm has differences between Arm- and Thumb-assembly. Most notably, the conditionals are handled differently.
Was This Post Helpful? 0
  • +
  • -

#23 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: Cross-Platform Assembly Language?

Posted 31 January 2019 - 10:58 PM

BTW, I've been under the impression that LLVM uses bytecode interpreter, like Java.
And .NET is a bytecode interpreter with a huge bunch of libraries.
Was This Post Helpful? 0
  • +
  • -

#24 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2728
  • View blog
  • Posts: 4,369
  • Joined: 21-June 11

Re: Cross-Platform Assembly Language?

Posted 01 February 2019 - 07:36 AM

View Postturboscrew, on 01 February 2019 - 06:58 AM, said:

BTW, I've been under the impression that LLVM uses bytecode interpreter


LLVM has a JIT compiler, which falls back to an interpreter on unsupported platforms. However, LLVM's primary use is as an AOT compiler. Clang, the Swift compiler, the Rust compiler, GHC etc. all produce AOT-compiled native executables (using LLVM).

Quote

like Java.


The HotSpot VM (used by both the Oracle JDK and OpenJDK) is an interpreter with a JIT - not a pure interpreter.

Quote

And .NET is a bytecode interpreter with a huge bunch of libraries.


.NET only JIT-compiles - it does not have an interpreter (that's true for Microsoft's implementation at least - I don't know about Mono).
Was This Post Helpful? 0
  • +
  • -

#25 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: Cross-Platform Assembly Language?

Posted 01 February 2019 - 10:59 AM

Hmm, looks like .NET is doing bit of both. From Wikipedia:

Quote

Languages which target a CLI-compatible runtime environment compile to CIL, which is assembled into an object code that has a bytecode-style format. CIL is an object-oriented assembly language, and is entirely stack-based. Its bytecode is translated into native code or—most commonly—executed by a virtual machine.


I think the "virtual machine" here refers to what was once known as "pseudoprocessor".
Was This Post Helpful? 0
  • +
  • -

#26 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2728
  • View blog
  • Posts: 4,369
  • Joined: 21-June 11

Re: Cross-Platform Assembly Language?

Posted 01 February 2019 - 11:21 AM

I'm pretty sure that "executed by a virtual machine" is either meant to refer to JIT compilation or just wrong. If you scroll down to the "Execution" section in the wiki article, it lists only JIT and AOT as possible ways to execute CIL code. As do any other sources I could find - I could not find any official sources claiming that .NET features a bytecode interpreter that's run before JITting the way HotSpot does it.
Was This Post Helpful? 0
  • +
  • -

#27 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: Cross-Platform Assembly Language?

Posted 03 February 2019 - 09:59 PM

The article says that CIL is compiled to bytecode and that's translated to native code or executed by a virtual machine.
Not the CIL itself.
Was This Post Helpful? 0
  • +
  • -

#28 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2728
  • View blog
  • Posts: 4,369
  • Joined: 21-June 11

Re: Cross-Platform Assembly Language?

Posted 04 February 2019 - 05:04 AM

Sorry for being imprecise, I meant the byte code, not the assembly code. As long as we agree that "executed by a virtual machine" here means JITted rather than interpreted in a more conventional sense, we mean the same thing.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2