Skip to content

Instantly share code, notes, and snippets.

@acoomans
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save acoomans/a27a8f1de0a89ceff389 to your computer and use it in GitHub Desktop.

Select an option

Save acoomans/a27a8f1de0a89ceff389 to your computer and use it in GitHub Desktop.
ARM asm "hello"
// hello world example
// llvm ARM assembly
//
// https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/iPhoneOSABIReference.pdf
// http://www.opensource.apple.com/source/xnu/xnu-2782.1.97//bsd/kern/syscalls.master
//
// void p();
.data
message:
.ascii "hello\n"
#ifndef __aarch64__ // assembler-with-cpp
.text
.global _p
.align 4
_p:
push {r4-r7, lr} // save LR, R7, R4-R6
add r7, sp, #12 // adjust R7 to point to saved R7
push {r8, r10, r11} // save remaining GPRs (R8, R10, R11)
sub sp, sp, #36 // allocate space for local storage
vpush {q4-q7} // save NEON registers
mov ip, #4 // syscall for write
mov r0, #1 // stdout fd
ldr r1, =message
mov r2, #6 // length of message
swi #0 // or svc 0x80
vpop {q4-q7} // restore NEON registers
add sp, sp, #36 // deallocate space for local storage
pop {r8, r10, r11} // restore R8-R11
pop {r4-r7, pc} // restore R4-R6, saved R7, return to saved LR
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment