Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Platform/Architecture Assembly Language

I know that assembly language is typically not cross-platform. And even with things like NASM you would still need different code for different architectures and platforms which have different runtimes and implementations of things such as interrupts. But if someone wanted to program in assembly language because they liked it, is there any implementation of a cross-platform cross-architecture assembly language?

Edit:

What about not assembly in the traditional sense, but a low-level programming language which looks a lot like assembly?

like image 586
Hophat Abc Avatar asked May 16 '12 04:05

Hophat Abc


2 Answers

I think Donald Knuth's MMIX is what you may be interested in. Knuth writes programs in his The Art of Computer Programming book in this machine/assembly language. To date no CPU supports it directly. There are only emulators. Oh, someone made an FPGA that can run it. But that's about it.

like image 187
Alexey Frunze Avatar answered Sep 22 '22 22:09

Alexey Frunze


LLVM is a low-level language (whose purpose is a compiler backend) that looks a lot like AT&T assembly, if not 10x worse. Here's an example:

define i32 @add_sub(i32 %x, i32 %y, i32 %z) {
entry:
  %tmp = add i32 %x, %y
  %tmp2 = sub i32 %tmp, %z
  ret i32 %tmp2
}

This is roughly equilavent with the following hand-written x86 assembly:

; Body
mov eax, edi
add eax, esi
sub eax, edx
ret

LLVM llc 3.3 generates the following code (indented differently for readability):

    .file    "add_sub.ll"
    .text
    .globl    add_sub
    .align    16, 0x90
    .type    add_sub,@function
add_sub:                        # @add_sub
    .cfi_startproc
# BB#0:                         # %entry
    lea    EAX, DWORD PTR [RDI + RSI]
    sub    EAX, EDX
    ret
.Ltmp0:
    .size    add_sub, .Ltmp0-add_sub
    .cfi_endproc


    .section    ".note.GNU-stack","",@progbits

The relevant code is this:

lea    EAX, DWORD PTR [RDI + RSI]
sub    EAX, EDX
ret

As you can see, LLVM has a very powerful optimizer. It is probably the closest that you're going to get.

like image 36
kirbyfan64sos Avatar answered Sep 20 '22 22:09

kirbyfan64sos