Slashdot Mirror


PowerPC Assembly Language

Josh Aas writes: "I've been looking for a way to learn PowerPC assembly language for a while now. My search for books only led to extremely out-of-date publications, and the whole ordeal was generally frustrating. I was amazed at the lack of documentation. Even Motorola and IBM's documentation resources (on the web) were lacking anything of use to me. However, it turns out that Apple provides a pretty good free tutorial on the subject. It's tailored for coding in Mac OS X, but I imagine it would be just as useful in any PowerPC environment. For some reason it includes instructions for the Intel architecture. Perhaps this has to do with the fact that Darwin runs on x86 as well."

10 of 35 comments (clear)

  1. PPC Altivec assembly information by statusbar · · Score: 3, Informative

    Is available at here

    --jeff
    --
    ipv6 is my vpn
  2. The real use of assembly by Snowfox · · Score: 5, Informative
    To those asking "why?" ...

    The real use of learning assembly is to validate your compiler output. It's rare to want to code much from the ground up in assembly anymore, save hardware-banging code, but knowing assembly still makes all the difference.

    Yes, most compilers will perform 1,001 optimizations, but the final bit of optimization you can eck out demands that you profile, examine the hot points, and replace them with assembly or restructure your C with a good idea of the code you really want it to generate.

    You'll still find things that the compiler engineers haven't thought of, or were lazy about implementing, or operations which implement unneccessary logic/precision.

    For example, sometimes it's best to hoist an expensive calculation -into- a loop because it fits where the processor otherwise stalls, but most compilers take the opposite approach. It's tough to force a C compiler to do this, because most want to hoist code -out- of loops when possible, assuming it's cheapest.

    Dependency on non-native signedness, float format or type sizes can mean that shifts, transcendental math, type conversion, etc is being done in software when a single opcode is what you expected.

    Understanding the code will tell you if something unusual is happening, such as non-native sized bools or less than optimal variables being turned into register variables.

    Some operations are simply not available to the C-only programmer. Subsequent lookups to sin/cos operations can be combined into a single opcode, but I've yet to see it done by any compiler. It's only available in assembly.

    The PowerPC offers a rough inverse/division approximation which is faster than a real divide, and is good enough for operations only requiring low precision or an approximation... also completely inaccessible to C code.

    Knowing a variable is guaranteed to be within a certain range or of a fixed set of values at a certain point can let you get away with all kinds of murderous assumptions which it's impossible to express in C.

    That said, I haven't seen a single PPC assembler reference that was half as good as just looking at the code. Look at code, look at a lot of code, and past that, just look at system implementors' documentation. x86 through Pentium III aside, most current assembler books are just fluff, are wrong about half the pipelining, omit a million useful optimzations and don't cover the real story at all. It's really gotten to the point where the only real way to learn is by doing and doing and doing.

  3. PowerPC Documentation from Motorola by Strype · · Score: 4, Informative

    I'm working on an embedded PowerPC 603e and was able to find some descent documentation on the 32-bit PowerPC instruction set in general from Motorola's home page. I know you said you checked there, but I had a difficult time tracking it down myself. So in case you missed it, the name of the document is PowerPC Microprocessor Family: The Programming Environments for 32-Bit Microprocessors . I ordered a printed copy from their literature center, and a week later I got a nice little green book that has already proven to be indespensable.

    1. Re:PowerPC Documentation from Motorola by buserror · · Score: 2, Interesting

      I agree that the Moto doc is quite useful, having a reference on all the opcodes proves indispensable as soon as you need to *write* some code.

      If you just want a few lines of assembly, write a small C function that does roughtly what you want, disassemble it and 'adopt' the generated assembly into your own piece.

      One very useful notation in codewarrior is that you can specify the register to use for parameters, it helps a lot when doing those things:
      long blah(long p1 : __r10, long p2 : __r11) : __r4 {..... }

      For patching stuff, I've found that using CodeWarrior assembly functions is extremely useful too. As well as for getting the hex value for opcodes from the disassembled output, saves a trip to the reference book.

  4. Re: A whole different reason by CMiYC · · Score: 2

    A completely different reason for wanting know Assembly language is not related to software. If you are a hardware design engineer, Assembly Language can be invaluable. I work for a company that makes Logic Analzyers and the most popular embedded processors is the PowerPC family. Our Logic Analyzers have a built in inverse assembler. Many Many times hardware engineers will look at the IA to determine what was going on, on the bus. Granted, they don't care what C instructions were being executed. They want to know, at the roots, what was the processor doing.

    I think its very unlikely nowadays someone would write a computer application in assembly laungage. It would take way to long. But in the embedded world there are tons of reasons to know assembly. At the very least, everyone should know how to read it....

  5. A few good links by Anonymous Coward · · Score: 2, Informative
    PowerPC

    Technical Library

    PowerPC FAQ

    Lightsoft: Beginners Guide to PowerPC Assembly Language

    March 95 - Balance of Power: Introducing PowerPC Assembly Language

    PowerPc Architecture

    PowerPC Library

    The Metroworks Code Warrior documentation also has some helpful stuff. I found a copy online a while ago, but it's gone now.

  6. x86 instructions by selectspec · · Score: 3, Funny
    For some reason it includes instructions for the Intel architecture

    I thought the Power PC was x86 compatible.

    --

    Someone you trust is one of us.

    1. Re:x86 instructions by karlm · · Score: 2, Interesting
      You would have to re-engineer the instruction set in order to add more registers. You would break backward compatability or make a totally new set of really long instructions that use the new registers. Both solutions have no advantage if you're still going to call it x86.

      It's just a really klugy instruction set. Floating point was added after the fact. IIRC, you have to multiply something in EAX by something pointed to by ESX or some such. This means you end up doing lots of needless loads and stores and loads and stores if, for instance, you're dealing with even a small system of polynomial equations.


      Your modern x86 CPUs can do "register aliasing" to try and overcome some of this register thrashing and to allow more parallelism, but aliasing circitry takes up realistate.


      Allowing self-modifying code is also a pain in the ass (PPC simply does not allow it) if you're going to try and run the instruction set non-natively (such as on the P4 core). Self-modifying code will thrash the P4's "translation cache". Memory pages have three permissions (read, write, execute) just like Unix files. However, several of the eight combinations are not allowed by the instruction set. This causes some minor security problems. (I forget which modes cannot be set. You can argue that some of them are useless as the x86 architects did, but there are some non-obvious situations where you might want some of the stranger modes.)


      People also complain that the x86 has too many addressing modes. IMHO, they should design instruction sets to be simple and allow for simple emulation. They know that they'll be emulating it on a more advanced core later down the line or shipping with an emulator in the BIOS or some such, so they might as well make their lives easier. IBM had the right idea with OS/390. Basically they designed the hardware and low level system such that the user never saw any code running on bare metal. The "OS" that the user saw was running in something like VMWare. Linux for S/390 runs in an OS/390 partition (basically a virtual machine) and never on the bare CPU. This has lots of advantages for security, stability, modularity, isolation, and maintainability, as well as ease of migration on to the next generation.



      There are reasons Intel is migrating from x86 on the high-end CPUs. Don't get me wrong, I'm a big AMD fan, but I think sledgehammer is going in the wrong direction. I woould much prefer that AMD made a PPC, SPARC, ARM, or MIPS instruction set cpu with on-die x86 emulation. We've been doing x86 emulation on a RISC core since the original Pentium chip. It wouldn't take much realistate to expose the RISC or VLIW instruction set as well.

      --
      Copyright Violation:"theft, piracy"::Anti-Trust Violation:"thermonuclear price terrorism"<-Overly dramatic language.
    2. Re:x86 instructions by Rogerborg · · Score: 2
      • I thought the Power PC was x86 compatible.

      Like horses and donkeys, but they invariably produce a sterile hybrid called the Transmeta.

      --
      If you were blocking sigs, you wouldn't have to read this.
  7. More simply by karlm · · Score: 2, Interesting
    More simply, instuction sets are designed based on a set of asumptions. The x86 instruction set was based on a set of assumptions that was true 20 years ago. x86 assumes that memory is expensive and compilers don't optimize well, so it's got lots of nifty little optimized instructions for doing common (and not so common) tasks and uses variable length instructions to make the code more compact.


    RISK instruction sets assume you don't mind having slightly larger code segmets if it means that most of your instructions execute in one clock cycle and you can up your clock rate (this is why the pentium family uses RISC cores). It also assumes you don't want to pay in transistors (and power and heat) for rarely used instructions. It also assumes you have compilers that a good enough so that you don't pay too high a penalty for not having those scan opcodes, having to work with only a couple of addressing modes, etc.


    VLIW takes this one step further. You don't mind increasing your code size because it means that your compiler has lots of time (comparatively) to figure out how to do multiple simultaneous issues in order to maximize your performance per transistor by explicity putting each issue into the verly long instruction. This assumes that you have very smart compilers. Unfortunately, it also means that your instructions are big. If clock multipliers continue to climb, you may see VLIW instruction sets, but decompressors on the die in order to increase the appearent memory bandwidth.


    Note that this progression in instruction sets represents a progressive moving of certain aspects of the CPU somplexity from the CPU core into the compiler. This allows the limited die realestate to be used for more ALUs, more Cache, smarter branch prediction, "SMP on a chip", etc. while continuing to allow the price of CPUs to fall.


    You can do on-chip emulation of the legacy insstruction sets (like on the P4 and even the Itanium), but it's baggage you have to drag arround even when running your native code. Software emulation of the legacy hardware seems more appropriate. If we all switched to some VILW CPUs now, in another 3 years (being pessimistic), Bochs (or another emulator) running on those CPUs would run the legacy code as fast as today's machines, and would run native code much faster.

    --
    Copyright Violation:"theft, piracy"::Anti-Trust Violation:"thermonuclear price terrorism"<-Overly dramatic language.