Beginner's Guide For Calling Functions (ASM)
Beginner's Guide For Calling Functions (ASM)

NOTE: This is for real code creators who already know how to read/write ASM.

Chapter 1: Intro

Mario Kart Wii was written in C++. Thus, it contains many generic C++ type functions (such as memcpy, memset, printf, sqrt,etc). Obviously, the game has its own unique functions as well such DWC_Auth, DWC_Login, etc.

You can create a cheat code by including the calling of one of these functions or just calling the function by itself. The majority of the time, these functions will start off with an ASM instruction that uses the stack frame (aka sp, aka r1) in some way.

During a subroutine, certain instructions will occur, then a 'branch then link' (bl) instruction will follow. After the 'bl' instruction, you will be at the beginning of some sort of function call. The end of a function call results in a Branch to Link Register (blr).

I won't get into all the endless technical details of subroutines in Power PC ASM, this guide will simply demo how to call some very basic functions.

A list of generic C++ functions for MKW can be found HERE (PAL); some Wii & MKW specific functions are also included. Credits to Megazig for the original list. Credits to Star for finding the list and posting the thread plus additional new functions. Credits to RiiDefi for also the addition of new functions.

Chapter 2: Manipulating the Link Register to Call a Function

You should already know what the Link Register is since you know some ASM. An easy way to call a function, is to have the address of that function in the Link Register, then branch to the Link Register. The function called OSRestart (responsible for restarting the game/disc) starts at address 0x801A8688 (PAL). Let's look at a set of ASM instructions below to see how we would call that function:

lis r12, 0x801A #Set 1st half address of PAL OS Restart
ori r12, r12, 0x8688 #Set 2nd half address
mtlr r12 #Copy value of r12 (0x801A8688) to the Link Register
blr #Branch to Link Register (Call/Start the function)

Once the blr instruction is executed, you will be sent to address 0x801A8688 and start executing the following ASM instructions that are there in memory. If one were to make a cheat code out of the above list of ASM instructions, this will cause the game/disc to reboot whenever that cheat code is used/activated.

A completed activate-able code of this function is located HERE

Chapter 3: Arguments

Certain functions need 'arguments' established before being called or else the calling of said function will cause the game to freeze or black-screen. Usually the game prefers starting off with r3 as the first argument. Then proceeding to r4, then r5 etc etc for any other added arguments if required.

If a certain function you are calling is not working or you need to figure out what the arguments are, it is best the take the address of said function and set an instruction breakpoint on Dolphin. Do whatever is necessary in the game to make the game call the function. Then the game will 'break'. Take a look at r3, r4, and r5. Sometimes the register values are actual integers values, or they are memory addresses pointing to the location of necessary integer values. They can also be memory addresses that hold another address which points to the location of a desired integer value.

The function known as SCGetSimpleAddressData has 1 argument. This function is responsible for grabbing your country code (byte), residence code (byte), and globe location/ (word) from your SYSCONF file of your Wii NAND. The argument (r3) acts as a 'reference pointer/navigator' of where the country code and globe location will be stored at in mid mem80. r3's exact value is your country code will be stored. r3's value plus 0x2 is where your region residence code will be stored. r3's value plus 0x1004 is where your globe location will be stored.

Chapter 4: Conclusion

As you can see, this is simple ASM. Unfortunately, there is no database/list/reference of arguments for functions calls that require them. Calling/utilizing some of these functions can get very complex. I am by no means an expert in any way, shape, or form in regards to function calls/utilization. If you have more questions, it may be best for you join the discord server (; there are others in this server who know a lot about these functions.

Forum Jump:

Users browsing this thread: 1 Guest(s)