08-14-2024, 05:55 PM
So I was doing it wrong all along?
Make it to 10,000
|
08-14-2024, 05:55 PM
So I was doing it wrong all along?
08-15-2024, 12:36 AM
Very much so, yes. (I'm assuming you're a vertebrate, otherwise idk)
My username is in Scottish Gaelic. If you speak that language, please tell me how to pronounce it properly.
The best source I've got so far is this: https://learngaelic.scot/dictionary/inde...word=false
08-15-2024, 01:22 AM
Date: 14 Aug 2024
Name: Silicosis DDR 1:51.323
08-15-2024, 02:18 AM
Voluntary compliance
08-15-2024, 02:35 AM
You know I work
08-15-2024, 02:58 AM
(This post was last modified: 08-15-2024, 03:56 AM by Fifty.
Edit Reason: tutorial update
)
Utilizing the Condition Register
For Advanced ASM Coders Chapter 1: Intro Requirements:
Are your codes ending up with "countless" branches and branch labels? Your codes are in need of some spring cleaning. Sometimes codes that have an excessive amount branches end up "unreadable", making it difficult for others to understand your code or help you debug any errors. Chapter 2: Condition Register Fundamentals When you execute any plane jane comparison instruction such as.... Code: cmpwi r0, 100 ...you are actually telling Broadway to run a check and then place the result of said check in Condition Register Field 0. What is Condition Register Field 0? First thing's first. The register you see in Dolphin that is named "CR" is the Condition Register. It contains the results of previously executed Compare Instructions. Conditional Branch Instructions (i.e. beq) read the data of the Condition Register to determine whether or not a branch route/jump is taken. The Condition Register contains 7 fields. Field 0 (cr0) thru Field 7 (cr7). STUVWXYZ S = cr0 T = cr1 U = cr2 etc etc.. Each field (crF) takes up one DIGIT (half-byte) in the CR. Thus, each crF contains 4 bits of data. You can specify which crF to place the result of the compare instruction in. By default, if no crF is specified in your compare instruction, then cr0 will be used. Code: cmpwi r0, 100 is short for... Code: cmpwi cr0, r0, 100 If you wish to use cr7 instead of cr0, you would write the instruction like this... Code: cmpwi cr7, r0, 100 An important thing that you must keep in mind is that if you make a comparison that is NOT using cr0, you must also specify the crF in the subsequent branch instruction. Like this... Code: cmpwi cr7, r0, 100 In conclusion, any crF that isn't cr0 must be specified in both compare and branch instructions. Chapter 3: Condition Register Field Bits and Examining Branch Instructions Now that you know there are 7 crF's and how to use each one in your comparison + branch instructions, let's cover the crF bits and what each bit represents. Each crF has 4 bits of data that uses the following structure.
CR Bit Table LT GT EQ SO crfX 0 1 2 3 crf0 4 5 6 7 crf1 8 9 10 11 crf2 12 13 14 15 crf3 16 17 18 19 crf4 20 21 22 23 crf5 24 25 26 27 crf6 28 29 30 31 crf7 Whenever a bit in the crF is high, the condition was true FROM THE MOST RECENT comparison instruction. Whenever a bit was low, the condition was false FROM THE MOST RECENT comparison. Multiple bits can be flagged high and/or low from a comparison instruction. Now that you understand the crF bits, let's go over what branch instructions actually do. Code: bge (branch if greater than or equal) = checks bits 0, if bit is low, branch is taken The branch instruction checks the bits of the crF that is specified in the instruction. Example: 'bge- cr7' checks LT bit of cr7. If low, branch is taken. Chapter 4: Condition Register specific instructions Before going into the CR specific instructions, we need to go over its 'format'. The 'format' of a typical CR instruction is this.. crXXX B, B, B #XXX = and, or, andc, orc, nor, xor, eqv Under this format, you need to specify the exact bit of the entire Condtion Register. The problem with this is that it now becomes a memory game and you have to refer to the earlier CR bit table provided in Chapter 3. Instead of doing that non-sense, you can use this handy formula... B = 4*crX+ZZ X = field number (0 thru 7) ZZ = lt, gt, eq, or so With this formula, all you need to remember to which Field you want to use and what bit type. So now the easier-to-remember 'format' is this.. crXXX 4*crX+ZZ, 4*crX+ZZ, 4*crX+ZZ --- CR Based Instructions:
Simplified Mnemonics:
Also, the following instructions may be handy for you...
Chapter 5: Cleaning up some Code Let's go over some basic examples of some "CR trickery" to help clean up code. Some examples below won't shorten the source at all (will be same compiled length), but the amount of branches (plus label names) are reduced. This is accomplished by using multiple crF's and using Condition Register specific instructions. Scenario 1: If r4 = 1 and r10 = r31, then go to 'store_data'. Otherwise, go to 'dont_store'. Typical Source Code: cmpwi r4, 1 New Source Code: cmpwi r4, 1 Scenario 2: If r4 = 1 or r10 = r31, then go to 'store_data'. Otherwise, go to 'dont_store'. Typical Source Code: cmpwi r4, 1 New Source Code: cmpwi r4, 1 Scenario 3: If r4 = 1 and r10 =/= r31, then go to 'store_data'. Otherwise, end_code Typical Source Code: cmpwi r4, 1 New Source Code: cmpwi r4, 1 Scenario 4: If r4 = 1 or r10 =/= r31, then go to 'store_data'. Typical Source Code: cmpwi r4, 1 New Source Code: cmpwi r4, 1 Scenario 5: If r4 = 1 then r10 must =/= r31, or if r4 =/=1 then r10 must = r31. If all requirments met go to 'store_data'. If not, go to end_code. Typical Source Code: cmpwi r4, 1 New Source Code: cmpwi r4, 1 Scenario 6: If r4 = 1, then r10 must = r31. However r4 can =/= 1 as long as r10 =/= r31. If all requirements are met go to 'store_data'. If not, go to end_code. Typical source Code: cmpwi r4, 1 New source Code: cmpwi r4, 1 Chapter 6: Final Example Let's say you have a value in r3 and it must be a valid Memory Address. Meaning a valid mem80, mem81, or mem9 address. If the address is not valid in any way, branch to the LR. An efficient way to write it would be like this (pretend r4 thru r7 are safe)... Code: lis r4, 0x8000 #0x80000000 And that's pretty much it. Happy coding!
08-15-2024, 09:32 AM
"Wow you're tall for a *micro* biologist" -- me yesterday
My username is in Scottish Gaelic. If you speak that language, please tell me how to pronounce it properly.
The best source I've got so far is this: https://learngaelic.scot/dictionary/inde...word=false
08-15-2024, 01:53 PM
omfg....
08-15-2024, 03:07 PM
.....
My username is in Scottish Gaelic. If you speak that language, please tell me how to pronounce it properly.
The best source I've got so far is this: https://learngaelic.scot/dictionary/inde...word=false
08-15-2024, 05:02 PM
Thewh
|
« Next Oldest | Next Newest »
|