Skip to content

Instantly share code, notes, and snippets.

@sandip4n
Created November 1, 2019 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandip4n/09b50786e88968faaecdf42360c85b1b to your computer and use it in GitHub Desktop.
Save sandip4n/09b50786e88968faaecdf42360c85b1b to your computer and use it in GitHub Desktop.
Hello World - PPC64LE Assembly
## Hello World - PPC64LE Assembly
## This is the ELF ABI v2 little-endian equivalent of
## https://developer.ibm.com/articles/l-ppc/#listing-4-hello-world-ppc64-assembly
##
## Cross-compile as shown below.
## $ powerpc64le-linux-gnu-as hello.s -o hello.o
## $ powerpc64le-linux-gnu-ld hello.o -o hello
##
## Author: Sandipan Das <sandipan@linux.ibm.com>
##
.data # section declaration - variables only
msg:
.string "Hello, world!\n"
len = . - msg # length of our dear string
.text # section declaration - begin code
.abiversion 2
.global _start
_start:
# write our string to stdout
li 0, 4 # syscall number (sys_write)
li 3, 1 # first argument: file descriptor (stdout)
# second argument: pointer to message to write
# load the address of 'msg':
# load high word into the low word of r4:
lis 4, msg@highest # load msg bits 48-63 into r4 bits 16-31
ori 4, 4, msg@higher # load msg bits 32-47 into r4 bits 0-15
rldicr 4, 4, 32, 31 # rotate r4's low word into r4's high word
# load low word into the low word of r4:
oris 4, 4, msg@h # load msg bits 16-31 into r4 bits 16-31
ori 4, 4, msg@l # load msg bits 0-15 into r4 bits 0-15
# done loading the address of 'msg'
li 5, len # third argument: message length
sc # call kernel
# and exit
li 0, 1 # syscall number (sys_exit)
li 3, 0 # first argument: exit code
sc # call kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment