I'm decided to improve my knowledge on the Cell platform, and the best way to get started seems to be to learn 64-bit PowerPC assembly given that the PPU uses this instruction set. Learning this will open the door to do some more interesting tricks with the architecture's low-level details.

There are some excellent articles at IBM developerWorks dealing with this subject, and thanks to the first one in an introductory series to PPC64 I've been able to write the typical hello world program :-)

Without further ado, here is the code!
# The program's static data


msg: .string "Hello, world!n"
length = . - msg

# Special section needed by the linker due to the C calling
# conventions in this platform.

.section ".opd", "aw" # aw = allocatable/writable

.global _start
.quad ._start, .TOC.@tocbase, 0

# The program's code


li 0, 4 # write(2)
li 3, 1 # stdout file descriptor
lis 4, msg@highest # load 64-bit buffer address
ori 4, 4, msg@higher
rldicr 4, 4, 32, 31
oris 4, 4, msg@h
ori 4, 4, msg@l
li 5, length # buffer length

li 0, 1 # _exit(2)
li 3, 0 # return success
You can build it with the following commands:
$ as -a64 -o hello.o hello.s
$ ld -melf64ppc -o hello hello.o
I'm curious about as(1)'s -a option; its purpose is pretty obvious, but it is not documented anywhere in the manual page nor in the info files.

Anyway, back to coding! I guess I'll post more about this subject if I find interesting and/or non-obvious things that are not already documented clearly anywhere. But for beginner's stuff you already have the articles linked above.

Go to posts index

Comments from the original Blogger-hosted post: