You've probably noticed by now, that while ASM itself is pretty much all simple instructions (add, multiply, branch, compare, subtract, etc), putting various instructions together to preform a designated task can be quite the challenge.
I've already recommended doing step-by-step testing to help you understand more. Another thing you can do is take a look at some of my older/simpler ASM writes. Those ASM codes are much easier to understand.
Here's a quick source I typed up, I didn't bother analyzing anything on Dolphin. This will give you an idea of how to start writing ASM and an idea of how to make the loops I was talking about earlier.
First thing's first, we need an area of memory for the user to fill in the name/clan tag they want. We will set a limit of 3 ASCII characters on it. We need a space in memory that never gets written to. An area of memory that fulfills this requirement is the Exception Vectors Area - http://mkwii.com/showthread.php?tid=1106
Considering 3 MKWii ASCII characters is 6 bytes of length, let's use memory addresses 0x80000A00 thru 0x800000A05. We can let the user set this value via two gecko-type RAM writes. We can load the values from the Exception Vector Area with the ASM code later. We cannot use a singular 32 bit (word) RAM write, because 6 bytes is more than a word in length.
RAM Writes
04000A00 XXXXYYYY
02000A04 0000ZZZZ
These RAM Writes will write the word XXXXYYYY at addresses 0x80000A00 thru A03. And halfword ZZZZ at 0x80000A04 thru A05.
--
Alright now onto the ASM code itself. Similar to the Mii name changer code, we will have the default instruction at the end, so it allows the game to load the new mii name (after changes were made) and allows us to use register 4 safely.
As per Register Safety protocol - HERE , we can always use r11 and r12. So we already have 3 registers at our disposal. However, to not worry about register safety, we will use what is called stack pushing/popping. Instructions to do this are also explained in the protocol thread..
Onto the source...
First thing's first, lets push the stack so we can freely use r14 thru r31.
stwu r1,-80(r1) # make space for 18 registers
stmw r14,8(r1) # push r14-r31 onto the stack
Next, let's grab the user's name/clan tag from the Exception Vector Area. We need to set a register to represent the beginning memory address of where the name/clan tag is. Let's use r14 for that...
lis r14, 0x8000 #Set upper 16 bits of r14 to 0x8000
ori r14, r14, 0x0A00 #Set lower 16 bits of r14 to 0x0A00
The ori is an unneeded instruction (there's a more optimized way to do this), but since you are a beginner let's keep it simple
lwz r15, 0 (r14) #The user's XXXXYYYY value is now in r15
lhz r16, 0x4 (r14) #User's ZZZZ value is now in r16
Alright at this point, we need to load our current Mii name and re-store back into dynamic memory (6 bytes further). We can't store the mii tag first, because we will lose part of our Mii name.
Now it's time for a loop. If you had read the Loop Pt1 thread, you will know we need to make our first loading loop address -0x4 in reference of what word we wanna load first.
Mii name starts at 0x2 in reference to r30. So.... 0x2 minus 0x4 = negative 0x2. Let's use r17 for that
addi r17, r30, -0x2
#r17 is set. Now we need a storing address. We need to store every Mii name word 0x6 further. But at the same time we need to account for the 0x4 margin.
So r30 + 0x2 = Where Mii name begins....
Thus 0x2 + 0x6 is 0x8 = Where we want Mii name to start at due to clan tag being added later..
0x8 - 0x4 for the 0x4 margin...So 0x4 is the value we need to add to r30...
addi r18, r30, 0x4
#r18 is now set to the loop's first storing address
We will use r19 as the register to hold each Mii word that is loaded and re-stored. We want this loop to only execute 5 times, since we are dealing with 5 total words. Let's use r20 to keep track of this...
li r20, 5 #Set r20 to 5
Let's start the loop!!
the_loop: #You need to label the loop. ASM tutorial teaches you how to set label names
lwzu r19, 0x4 (r17)
stwu r19, 0x4 (r18)
subic. r20, r20, 1
bne+ the_loop
This loop will execute only 5 times. At this point the Mii name has been re-stored! Let's add the Mii clan tag...
stw r14, 0x2 (r30)
sth r15, 0x6 (r30)
We are done! Let's pop the stack to recover r14 thru r31's values. And finish it off with the default instruction...
lmw r14,8(r1) # pop r14-r31 off the stack
addi r1,r1,80 # release the space
lhz r4, 0 (r30) #Default Instruction
Entire Source put together...
stwu r1,-80(r1) # make space for 18 registers
stmw r14,8(r1) # push r14-r31 onto the stack
lis r14, 0x8000 #Set upper 16 bits of r14 to 0x8000
ori r14, r14, 0x0A00 #Set lower 16 bits of r14 to 0x0A00
lwz r15, 0x0 (r14) #The user's XXXXYYYY value is now in r15
lhz r16, 0x4 (r14) #User's ZZZZ value is now in r16
addi r17, r30, -0x2 #Sets Loop 1st loading address
addi r18, r30, 0x4 #sets Loop 1st storing address
li r20, 5 #Set r20 to 5, how many times the loop will execute
the_loop:
lwzu r19, 0x4 (r17)
stwu r19, 0x4 (r18)
subic. r20, r20, 1
bne+ the_loop
stw r14, 0x2 (r30) #Store Clan Tag
sth r15, 0x6 (r30)
lmw r14,8(r1) # pop r14-r31 off the stack
addi r1,r1,80 # release the space
lhz r4, 0 (r30) #Default Instruction
Conclusion
Code compiled with RAM writes added (PAL)..
04000A00 XXXXYYYY
02000A04 0000ZZZZ
C20C6DD8 0000000A
9421FFB0 BDC10008
3DC08000 61CE0A00
81EE0000 A20E0004
3A3EFFFE 3A5E0004
3A800005 86710004
96720004 3694FFFF
4082FFF4 91DE0002
B1FE0006 B9C10008
38210050 A09E0000
60000000 00000000
This code WILL fail. There is no check for...
If user uses a tag less than 6 bytes in size.
If user's mii name (with assumed added tag) will exceed 10 characters
If user's original mii name exceeds 10 characters, which wouldn't even allow any tag to be added
Those are features you will need to add yourself to the ASM. Get your ASM fully working first before begin concerned w/ optimization. Good luck!
I've already recommended doing step-by-step testing to help you understand more. Another thing you can do is take a look at some of my older/simpler ASM writes. Those ASM codes are much easier to understand.
Here's a quick source I typed up, I didn't bother analyzing anything on Dolphin. This will give you an idea of how to start writing ASM and an idea of how to make the loops I was talking about earlier.
First thing's first, we need an area of memory for the user to fill in the name/clan tag they want. We will set a limit of 3 ASCII characters on it. We need a space in memory that never gets written to. An area of memory that fulfills this requirement is the Exception Vectors Area - http://mkwii.com/showthread.php?tid=1106
Considering 3 MKWii ASCII characters is 6 bytes of length, let's use memory addresses 0x80000A00 thru 0x800000A05. We can let the user set this value via two gecko-type RAM writes. We can load the values from the Exception Vector Area with the ASM code later. We cannot use a singular 32 bit (word) RAM write, because 6 bytes is more than a word in length.
RAM Writes
04000A00 XXXXYYYY
02000A04 0000ZZZZ
These RAM Writes will write the word XXXXYYYY at addresses 0x80000A00 thru A03. And halfword ZZZZ at 0x80000A04 thru A05.
--
Alright now onto the ASM code itself. Similar to the Mii name changer code, we will have the default instruction at the end, so it allows the game to load the new mii name (after changes were made) and allows us to use register 4 safely.
As per Register Safety protocol - HERE , we can always use r11 and r12. So we already have 3 registers at our disposal. However, to not worry about register safety, we will use what is called stack pushing/popping. Instructions to do this are also explained in the protocol thread..
Onto the source...
First thing's first, lets push the stack so we can freely use r14 thru r31.
stwu r1,-80(r1) # make space for 18 registers
stmw r14,8(r1) # push r14-r31 onto the stack
Next, let's grab the user's name/clan tag from the Exception Vector Area. We need to set a register to represent the beginning memory address of where the name/clan tag is. Let's use r14 for that...
lis r14, 0x8000 #Set upper 16 bits of r14 to 0x8000
ori r14, r14, 0x0A00 #Set lower 16 bits of r14 to 0x0A00
The ori is an unneeded instruction (there's a more optimized way to do this), but since you are a beginner let's keep it simple
lwz r15, 0 (r14) #The user's XXXXYYYY value is now in r15
lhz r16, 0x4 (r14) #User's ZZZZ value is now in r16
Alright at this point, we need to load our current Mii name and re-store back into dynamic memory (6 bytes further). We can't store the mii tag first, because we will lose part of our Mii name.
Now it's time for a loop. If you had read the Loop Pt1 thread, you will know we need to make our first loading loop address -0x4 in reference of what word we wanna load first.
Mii name starts at 0x2 in reference to r30. So.... 0x2 minus 0x4 = negative 0x2. Let's use r17 for that
addi r17, r30, -0x2
#r17 is set. Now we need a storing address. We need to store every Mii name word 0x6 further. But at the same time we need to account for the 0x4 margin.
So r30 + 0x2 = Where Mii name begins....
Thus 0x2 + 0x6 is 0x8 = Where we want Mii name to start at due to clan tag being added later..
0x8 - 0x4 for the 0x4 margin...So 0x4 is the value we need to add to r30...
addi r18, r30, 0x4
#r18 is now set to the loop's first storing address
We will use r19 as the register to hold each Mii word that is loaded and re-stored. We want this loop to only execute 5 times, since we are dealing with 5 total words. Let's use r20 to keep track of this...
li r20, 5 #Set r20 to 5
Let's start the loop!!
the_loop: #You need to label the loop. ASM tutorial teaches you how to set label names
lwzu r19, 0x4 (r17)
stwu r19, 0x4 (r18)
subic. r20, r20, 1
bne+ the_loop
This loop will execute only 5 times. At this point the Mii name has been re-stored! Let's add the Mii clan tag...
stw r14, 0x2 (r30)
sth r15, 0x6 (r30)
We are done! Let's pop the stack to recover r14 thru r31's values. And finish it off with the default instruction...
lmw r14,8(r1) # pop r14-r31 off the stack
addi r1,r1,80 # release the space
lhz r4, 0 (r30) #Default Instruction
Entire Source put together...
stwu r1,-80(r1) # make space for 18 registers
stmw r14,8(r1) # push r14-r31 onto the stack
lis r14, 0x8000 #Set upper 16 bits of r14 to 0x8000
ori r14, r14, 0x0A00 #Set lower 16 bits of r14 to 0x0A00
lwz r15, 0x0 (r14) #The user's XXXXYYYY value is now in r15
lhz r16, 0x4 (r14) #User's ZZZZ value is now in r16
addi r17, r30, -0x2 #Sets Loop 1st loading address
addi r18, r30, 0x4 #sets Loop 1st storing address
li r20, 5 #Set r20 to 5, how many times the loop will execute
the_loop:
lwzu r19, 0x4 (r17)
stwu r19, 0x4 (r18)
subic. r20, r20, 1
bne+ the_loop
stw r14, 0x2 (r30) #Store Clan Tag
sth r15, 0x6 (r30)
lmw r14,8(r1) # pop r14-r31 off the stack
addi r1,r1,80 # release the space
lhz r4, 0 (r30) #Default Instruction
Conclusion
Code compiled with RAM writes added (PAL)..
04000A00 XXXXYYYY
02000A04 0000ZZZZ
C20C6DD8 0000000A
9421FFB0 BDC10008
3DC08000 61CE0A00
81EE0000 A20E0004
3A3EFFFE 3A5E0004
3A800005 86710004
96720004 3694FFFF
4082FFF4 91DE0002
B1FE0006 B9C10008
38210050 A09E0000
60000000 00000000
This code WILL fail. There is no check for...
If user uses a tag less than 6 bytes in size.
If user's mii name (with assumed added tag) will exceed 10 characters
If user's original mii name exceeds 10 characters, which wouldn't even allow any tag to be added
Those are features you will need to add yourself to the ASM. Get your ASM fully working first before begin concerned w/ optimization. Good luck!