Cross Platform/Architecture Assembly Language-Collection of common programming errors
LLVM is a low-level language (whose purpose is a compiler nbackend) that looks a lot like AT&T assembly, if not 10x worse. Here’s an example:
define i32 @mul_add(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 code generated by this AsmJit code:
#include
#include
using namespace AsmJit;
typedef int (*FuncType)(int, int, int);
FuncType build_func(X86Compiler& c)
{
FileLogger logger(stderr);
c.setLogger(&logger);
c.newFunc(kX86FuncConvDefault, FuncBuilder3());
GpVar x = c.getGpArg(0);
GpVar y = c.getGpArg(1);
GpVar z = c.getGpArg(2);
GpVar tmp = c.newGpVar(kX86VarTypeGpd);
GpVar tmp2 = c.newGpVar(kX86VarTypeGpd);
c.mov(tmp, x);
c.add(tmp, y);
c.mov(tmp2, tmp);
c.sub(tmp2, z);
c.ret(tmp2);
c.endFunc();
return asmjit_cast(c.make());
}
This is the output:
; Function Prototype:
;
; IDX| Type | Sz | Home |
; ---+----------+----+----------------+
; 0 | Gpd | 4 | rdi |
; 1 | Gpd | 4 | rsi |
; 2 | Gpd | 4 | rdx |
;
; Variables:
;
; ID | Type | Sz | Home | Register Access | Memory Access |
; ---+----------+----+----------------+-------------------+-------------------+
; 0 | Gpd | 4 | [None] | r=1 w=0 x=0 | r=0 w=0 x=0 |
; 1 | Gpd | 4 | [None] | r=1 w=0 x=0 | r=0 w=0 x=0 |
; 2 | Gpd | 4 | [None] | r=1 w=0 x=0 | r=0 w=0 x=0 |
; 3 | Gpd | 4 | [None] | r=1 w=1 x=1 | r=0 w=0 x=0 |
; 4 | Gpd | 4 | [None] | r=1 w=1 x=1 | r=0 w=0 x=0 |
;
; Modified registers (5):
; GP : rax, rcx, rdx, rsi, rdi
; MM :
; XMM:
L.0:
; Prolog
push rbp
mov rbp, rsp
; Body
mov ecx, edi
add ecx, esi
mov eax, ecx
sub eax, edx
L.1:
; Epilog
mov rsp, rbp
pop rbp
ret
LLVM is probably the closest that you’re going to get.