Edit: I suddenly realized that I can write a C Hello World and look at the disassembled code if I have the tool. I'll see what I get.
I'm trying to write a simple Hello World program using an iBook G4 (Mac OS X with XCode 2.5), assembled by GNU assembler 1.38.
Surprisingly, there is VERY LITTLE material online for this architecture, even compared to CPUs from decades earlier such as 68K (yeah I know it was popular but PowerPC has been popular for a while too). All the IBM links are down, and even archive.org doesn't work because IBM just loves to redirect spiders I guess. There is only the more advanced 64-bit AIX stuff I think. The only book I could find is the "Programming the PowerPC (1994)" but it doesn't talk about assembly programming. There is also the NXP PowerPC 601 manual, but I don't understand it (more details below).
Anyway, I asked ChatGPT to write a program, and wasn't able to compile it after many hours of correcting (For a good laugh, I spent 30 mins convincing myself and ChatGPT that it actually should use ;
instead of #
for comments -> which I already knew years ago but it happened that the error message was very ambiguous and ChatGPT was so confident of it, so I didn't even think of it in the beginning). Here is the most current version:
.section __TEXT,__text .globl _start _start: # Write "Hello, World!" to stdout li r0, 4 ; System call number: write (Mac syscall table) li r3, 1 ; File descriptor: stdout lis r4, hello@ha ; Load the high part of "hello" address into r4 addi r4, r4, hello@l ; Add the low part to r4 li r5, 14 ; Length of the string sc ; Trigger the syscall # Exit the program li r0, 1 ; System call number: exit (Mac syscall table) li r3, 0 ; Exit status sc ; Trigger the syscall .section __TEXT,__cstring hello: .asciz "Hello, World!\n"
Error message (for the lis and addi lines):
Parameter error: expression must be absolute (parameter 2) Invalid mnemonic 'ha'
I managed to remove all errors except for the @ha
and @l
part -- I did find such examples on the Internet (e.g. in the as manual or on Godbolt if I use Power GCC) so I figured maybe it's just a PowerPC error. The NXP manual somehow doesn't even show a load SIMM to Register instruction (looks like all loads look like this: li RA, d(RC)
). I think I must have missed something.
Can you please let me know how to correct those two lines? And more importantly, can you please point me to a book or a website for some iBook4 assembly language programming tutorial? Prefer textbooks but manuals work too.