Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created April 26, 2020 08:33
Show Gist options
  • Save andrewrk/458a0bad6cac02009e48069d30b9ad5d to your computer and use it in GitHub Desktop.
Save andrewrk/458a0bad6cac02009e48069d30b9ad5d to your computer and use it in GitHub Desktop.
@0 = str("Hello, world!\n")
@1 = primitive(noreturn)
@2 = primitive(usize)
@3 = fntype([], @1, cc=Naked)
@4 = int(0)
@5 = int(1)
@6 = int(231)
@7 = str("len")
@8 = fn(@3, {
%0 = as(@2, @5) ; SYS_write
%1 = as(@2, @5) ; STDOUT_FILENO
%2 = ptrtoint(@0) ; msg ptr
%3 = fieldptr(@0, @7) ; msg len ptr
%4 = deref(%3) ; msg len
%sysoutreg = str("={rax}")
%rax = str("{rax}")
%rdi = str("{rdi}")
%rsi = str("{rsi}")
%rdx = str("{rdx}")
%rcx = str("rcx")
%r11 = str("r11")
%memory = str("memory")
%syscall = str("syscall")
%5 = asm(%syscall, @2,
volatile=1,
output=%sysoutreg,
inputs=[%rax, %rdi, %rsi, %rdx],
clobbers=[%rcx, %r11, %memory],
args=[%0, %1, %2, %4])
%6 = as(@2, @6) ;SYS_exit_group
%7 = as(@2, @4) ;exit code
%8 = asm(%syscall, @2,
volatile=1,
output=%sysoutreg,
inputs=[%rax, %rdi],
clobbers=[%rcx, %r11, %memory],
args=[%6, %7])
%9 = unreachable()
})
@9 = str("_start")
@10 = export(@9, @8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment