Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to FFH, where all your dreams come true!

ASM Lessons  (Read 6157 times)
Pages: 1 2 [3]
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1307] Logged
  • View Profile
  • share
  • [March 24, 2012, 07:50:49 AM]
Re: ASM Lessons
« Reply #40 on: March 24, 2012, 07:50:49 AM »
The next session will be sometime tomorrow afternoon (PST).  I presume that whoever wishes to join me tomorrow understands Xif's tutorial on the website's main page (Xif's ASM tutorial).

The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Blue Mage
AeroGP [Posts: 196] Logged
  • View Profile
  • share
  • [March 25, 2012, 01:25:41 AM]
Re: ASM Lessons
« Reply #41 on: March 25, 2012, 01:25:41 AM »
Your homework: grab Xifanie's Ability Requirements Hack (ARH). Transcribe each line and point out any and all pipeline hazards.

Hint: Whatever it says in BATTLE.BIN as an offset, add +0x67000... ~Formerdeathcorps
« Last Edit: March 25, 2012, 01:35:45 AM by AeroGP »
Quote from: Tycho
“There are a number of different factors impacting server connectivity on Xbox 360,” the spokesperson said. “It is a particularly complex server architecture and we continue to work with Microsoft to improve connectivity.”

I don’t want to bolster any “violent gamer” tropes, but that statement makes me want to improve the connectivity of my front two knuckles with their esophagus.  I wonder how Brenna would respond if I told her that “fidelity” was complicated.
Glain [Posts: 405] Logged
  • View Profile
  • share
  • [March 25, 2012, 06:29:07 PM]
Re: ASM Lessons
« Reply #42 on: March 25, 2012, 06:29:07 PM »
Gah. I keep hearing about how Square does things this way or that, when you're dealing with the specifics of how things like multiplication are done in the ASM. Almost every single thing you're attributing to Square is actually being done by their compiler. I'm not saying there aren't legit things to point out about Square's code (hardcoding is a big offender, and some of the stuff you mentioned about rounding errors is relevant), but a lot of this stuff... they probably didn't have anything to do with. As far as I know, for example, they probably did something like:

return (fix)(1/3) * number; // No FPU, using fixed point

and the compiler created something like:

lui r3,0x5555
ori r3,r3,0x5556
mult r3,r4
mfhi r2
jr r31
nop

It's not as if they went "HMMM... 0x55555556 is how to represent 1/3". Same with the percents. The 32 is probably because it's 2^5 and the compiler wanted to do a bit shift.

Also... you memorize opcodes?! That amazes me. Also, they're only 6 bits. Trying to break up an encoded instruction by byte isn't going to work that well. Opcodes are 6 bits, register indexes are 5, shift amount is... 5, I think... jump addresses are 26... it doesn't cleanly divide into eights (bytes). You need to use binary to represent them.

Regarding absorb... very interesting. Are you saying that if you do negative damage, it counts as absorb? The way the elemental  absorb routine (0x1870fc) does it, it checks to see if you absorbed the attack and if you did, it takes the HP damage, moves it to HP healing, sets the HP damage to 0, and sets the ability type to [HP Healing].
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1307] Logged
  • View Profile
  • share
  • [March 25, 2012, 08:05:28 PM]
Re: ASM Lessons
« Reply #43 on: March 25, 2012, 08:05:28 PM »
Quote
Regarding absorb... very interesting. Are you saying that if you do negative damage, it counts as absorb? The way the elemental  absorb routine (0x1870fc) does it, it checks to see if you absorbed the attack and if you did, it takes the HP damage, moves it to HP healing, sets the HP damage to 0, and sets the ability type to [HP Healing].

No, that's not what's supposed to happen, though I may have accidentally implied that.  All finalized damage in the game is treated as if it was signed, though.  This is why mult is used almost exclusively over multu in the damage calculation steps (and why you have 5555 5556 instead of AAAA AAAB).  Of course, it doesn't quite matter since when you store data from registers, the signs are ignored.  It's also worth noting that all the original loads of PA / MA / SP / X / Y are unsigned and the results are guaranteed within the part of the number line where unsigned = signed (often quite forcefully on the stat up/down routines), so there are no discrepancies with the results.  The fact both are used is probably a holdover of the production process: different teams worked on adjoining pieces of code, but one team used unsigned int, and other used signed int.

The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Glain [Posts: 405] Logged
  • View Profile
  • share
  • [March 26, 2012, 05:09:22 PM]
Re: ASM Lessons
« Reply #44 on: March 26, 2012, 05:09:22 PM »
The book I used shows 5 stages for MIPS instructions... basically the ones shown in this link.

Memory loading is where you have to watch out for delay (Load delay):

lbu r4,0x0034(r5)
addi r4,r4,1               # Oops, pipeline hazard - load delay - r4's value isn't loaded yet.

Memory storing may also have the same one command delay, but, well...?

sb r4,0x0034(r5)        # Save the value to memory...
lbu r4,0x0034(r5)       # Now load it from memory, even though it's still in the register, for no reason! \o/

And if you do that, then, well, uh...  :shock:
So there's nothing to worry about with storing values to memory, it's just the loading that you have to watch out for.

We talk about avoiding pipeline hazards here.
SaGa Frontier Hacker
Pickle Girl Fanboy [Posts: 1482] Logged
  • View Profile
  • Bio Research Lab
  • share
  • [April 04, 2012, 11:27:50 PM]
Re: ASM Lessons
« Reply #45 on: April 04, 2012, 11:27:50 PM »
FDC's Lesson on MIPS R3000A syntax

Pages: 1 2 [3]