Advertisement
BaSs_HaXoR

PPC64 Assembly Hello World

Oct 18th, 2014
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Source: http://www.ibm.com/developerworks/library/l-ppc/
  2.  
  3. .data                       # section declaration - variables only
  4.  
  5. msg:
  6.     .string "Hello, world!\n"
  7.     len = . - msg       # length of our dear string
  8.  
  9. .text                       # section declaration - begin code
  10.  
  11.         .global _start
  12.         .section        ".opd","aw"
  13.         .align 3
  14. _start:
  15.         .quad   ._start,.TOC.@tocbase,0
  16.         .previous
  17.  
  18.         .global  ._start
  19. ._start:
  20.  
  21. # write our string to stdout
  22.  
  23.     li      0,4         # syscall number (sys_write)
  24.     li      3,1         # first argument: file descriptor (stdout)
  25.                         # second argument: pointer to message to write
  26.  
  27.     # load the address of 'msg':
  28.  
  29.                         # load high word into the low word of r4:
  30.     lis 4,msg@highest   # load msg bits 48-63 into r4 bits 16-31
  31.     ori 4,4,msg@higher  # load msg bits 32-47 into r4 bits  0-15
  32.  
  33.     rldicr  4,4,32,31   # rotate r4's low word into r4's high word
  34.  
  35.                         # load low word into the low word of r4:
  36.     oris    4,4,msg@h   # load msg bits 16-31 into r4 bits 16-31
  37.     ori     4,4,msg@l   # load msg bits  0-15 into r4 bits  0-15
  38.  
  39.     # done loading the address of 'msg'
  40.  
  41.     li      5,len       # third argument: message length
  42.     sc                  # call kernel
  43.  
  44. # and exit
  45.  
  46.     li      0,1         # syscall number (sys_exit)
  47.     li      3,1         # first argument: exit code
  48.     sc                  # call kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement