Geekiness and life on the third coast

Assembly on the PPC

April 22, 2007 Fixed broken links.

January 26, 2007 Now that Apple has moved to an Intel chip there seems little reason to pursue this. It is still a very popular page on my main website, so I am adding it here so that people can use the comment section to add information and perhaps help others.

June 16th 2006 I received an email today telling the ‘hello world’ program was causing seg-faults on some computers and so I’m posting the corrected version along with the information on how to fix this seg-fault problem. We all know how much fun it is to hunt down seg-fault errors. It’s under off site and other examples below.

May 22 No time, no time!!! I received an email this week with an optimized version of strlen. I haven’t had a chance to do more than to save the email as a text file, but it is included here below for anyone who is interested. Send in examples, they will help others. I’ll post ’em as I can.

June 13th 2006 I’m finally settled enough to start digging through old email and work on some things here. I added two example programs submitted by Christopher Aubut and a link to his site in case he adds more examples. There is also a nice ‘how to do reverse engineering on a mac’ intro on his site.

May 7, 2005 All is chaos as we relocate from Boston to Houston. However I’ve received several emails and will post stuff as time allows.

Finding assembly language ‘how tos’ and ‘tutorials’ hasn’t been easy. It would seem there are few assembly programmers and fewer of them using a ppc. If anyone has simple examples or other information send it to me timestocome@gmail.com and I’ll post them here.

Times to Come Examples
The usual, prints a string ‘Hello World’ to the screen
(compile…. gcc helloworld.s -o helloworld )
hello world
Jumpstart calls the fibonacci assembly program and catches the fibonacci return value. Also shows how to do a loop and counter.
(compile…. gcc jumpstart.c fibonacci.s -o fibonaccinumber )
Corrected version with comments Example of an if..else statement

ResourcesHow to’s
Old issues of Mac Tech have several articles on how to program in PPC Assembly. This links direct to one, use the search tool and you’ll find several more articles.
PPC Shellcode Assembly A fun how to, explains incorporating assembly into C code and using gdb to debug code. You’ll never forget to check your buffer input again.
IBM Introduction to assembly on the PowerPC Has short intro and several ‘hello world’ examples, I couldn’t get the examples to work.
Beginners Guide PowerPC Assembly Language
Start here if you are new to assembly Balance of Power: Introducing PowerPC Assembly Language a light weight overview
PC Assembly Language (has tutorial and other info)
Introduction to Microcontroller notes has a nice section on ppc assembly with examples.
Uniformed.org has a short introduction to ppc assembly.

Art of Assembly Language Programming and HLA has several downloadable books on assembly
PowerPC Microprocessor Family: The Programming Environments for 32-Bit Microprocessors PDF manual with registers, op-codes and other information
PowerPC Assembly Quick Reference op-code chart
PowerPC Assembly QuickRef another op-code chart
OpenMac: References a list of Mac hardware docs on the net
PowerPC Technical Tidbits overview stack, registers etc
PowerPC Compiler’s Writer’s Guide TOC lots of info on the hardware and lots of assembly code snippets.
The PowerPC Architecture: A Programmer’s View article overview on the hardware
Mac OS X Assembler Guide op-codes, syntax, register info, addressing modes
a xhref=”http://hpcf.nersc.gov/vendor_docs/ibm/asm/alangref.htm” mce_href=”http://hpcf.nersc.gov/vendor_docs/ibm/asm/alangref.htm” >Assembler Language Reference op-codes, syntax, addressing, assembling and linking

Offsite and submitted examples
Hello World with seg-fault error removed and information on this particular seg-fault problem.
Original asm and condensed asm strlen
PSYBALAND has a tic-tac-toe and hex dump program posted.
Several examples of assembly including some ppc examples
PowerPC Numerics ( has C and Assembler )
Macintosh Freeware by Cliff Harris several PPC Assembly programs are here
PowerPC Architecture and Assembly Language a Simple Example a lecture on ppc assembly with simple examples
Tic-Tac-Toe the computer plays itself showing step by step each move it has made
Hex Dump this program takes a file as input and prints the corresponding hex

gcc cprogram.c -S
This will give you an assembly file cprogram.s of your c code Which you can then compile gcc -o cprogram cprogram.sSystem call numbers ( for register r0 ) can be found in /usr/include/sys/syscall.h

gdb The GNU debugger

Basic syntax
instruction destination, sourcesource register may have a displacement as well
command rxx, (rxx) ; displacement is 0
command rxx, 4(rxx) ;comments ‘#’ in first column, or ‘;’ anywhere

Instructions can be from a register to memory, memory to a register, or between registers. Load and store instructions have access to memory. (li/stw )Immediate means use the value given in the instructionLabels are followed by colons ( Total: or FunctionOne: )
Adding a ‘.’ to an instruction applies it to the Condition Register exempt for cmp which always effects the Condition Register