# ASM Aitch: I don't write much melee asm, but here's some things I've picked up by hacking on unclepunch's asm. Here are some things you should know before diving into here, and some questions I have. Clown: I have written a good amount of melee asm. I've added some useful information I have here. If you have any questions, reach out on the discord. ## Overview PowerPC (PPC) is an instruction set architecture (ISA) that used to be used in computers and game consoles in the 90s and 2000s, notably in several Apple products, the Xbox 360, the PS3, and the GC/Wii/Wii U. Specifically, the GameCube and Wii use an embedded, big-endian, 32-bit version of PowerPC on their CPUs. ## Resources: - [IBM PPC User Instruction Set Architecture](https://files.decomp.dev/ppc_isa.pdf) - [IBM PPC Compiler Writer's Guide](https://files.decomp.dev/IBM_PPC_Compiler_Writer's_Guide-cwg.pdf) - [Beginner to advanced tutorials for PowerPC](https://mariokartwii.com/showthread.php?tid=1114) - [rlwinm/rlwimi/rlwmn Decoder](https://celestialamber.github.io/rlwinm-clrlwi-decoder/) - [Decompilation project for Melee](https://github.com/doldecomp/melee) - [Decomp Intro](https://github.com/doldecomp/melee/wiki/Decomp-Intro) You should prioritize reading Section 2 and Appendix A of the Compiler's Writing Guide. Also, Section 1.6 and Appendix B of the User Instruction Set Architecture. The decompilation project is useful for understanding Melee's code. If you have an address of a Melee function, you can grep the decomp codebase and see if it's been decompiled. Even if it hasn't been, it's easier to search around for related code within that repo than it is to work within the dolphin debugger. If you're interested in learning more, you should read the Decomp Intro. ## Notes: - **The numbers 0..32 are allowed as registers!** You may run into silent errors where you expect to use a constant value but end up using a register. The most common place to see this are in math instructions - `addi r3, r3, 10` can be accidentally written as `add r3, r3, 10` and introduce a bug. - If you see a load with offset around 0x23ec-0x2424 in OSD related code, it's probably reading or writing to `struct MEX` or `struct TM` in `struct FighterData` in `MexTK/include/fighter.h`. - **Don't be afraid of the dolphin debugger!**. Use the latest version of dolphin. - Everything in both `ASM/Globals.s` and `ASM/training-mode/Globals.s` are helper macros. These are imported into most other ASM files. `ASM/Globals.s` is outdated, use `ASM/training-mode/Globals.s` for new asm files. ### `mflr` Because ASM files could be placed anywhere, you can't exactly just load a label as an address in a register. To get around this, there is an extremely common pattern using the `mflr` instruction. When the `bl