Jump to content
  • 0

How to Begin Learning ASM?


FixtySour
 Share

Question

First off, If any of you remember me, I'd like to begin by saying that when me and my friend 'Gazpacho146' decided to attempt to develop a multiplayer mod for Majora's Mask, we were way over our heads. Although we knew a small bit of ASM, it really was just that - a very minuscule, unorganized knowledge of what it was and how it worked. The project was obviously destined to be short-lived.

 

But now that I know how much I don't know about ASM, there is so much that I do want to know. So I've come here asking all of you who may know about ASM, how it works, or even where some resources might be which I could use to begin my long trek to learn assembly. If you have anything of relevance, I would be extremely thankful if you might share it with me. Anything that also might involve N64 specific ASM would be great as well.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I should really update my tutorial and add on the assembly hacking section...

 

DeathBasket, spinout, and sakura would be of great help to you. This topic is something that you probably won't get right away and it takes time to figure out how everything works. Here are some tips I offer you:

 

  • Grab an assembler. I prefer to use Renegade64 and mips-gcc or mips-as.
  • Learn the Opcodes, what they do, and their syntax.
  • Have some knowledge of how bit-wise arithmetic works. You'll need it for tons of things.
  • Know the importance and usage of all registers.
  • Know how the CPU of the N64 works.
  • Become acquainted with the OoT/MM RAM map and the structure of certain data types.
  • Be comfortable with working with the stack pointer (register sp).
  • It'll really help to start using an emulator with a decent debugger (nemu).
  • Knowing the boundaries of signed and unsigned values is very important!
  • It would do you go know the terminology used to describe numbers of bytes:

    ---Byte : 0x01 byte (8 bits)

    ---Halfword : 0x02 bytes (16 bits)

    ---Word : 0x04 bytes (32 bits)

    ---Doubleword : 0x08 bytes (64 bits)

Here are a few personal tips...

  • Using a JAL (Jump and Link) will replace the value currently in register ra with an address to return to (like a function call). It's good to preserve any values contained in registers in the stack and restore them later. Make sure to update the stack when you're no longer using it.
  • When making a function call, arguments beyond four (a0, a1, a2, a3) must be stored at stack + 0x10.
  • Return values are stored in v0 and v1.
  • Registers at, gp, and k1 are usually free to use after the game boots up.
  • You don't have worry about preserving registers besides ra, all saved temporaries, and return values if you're code comes at the end of a function/routine (like right before a JR RA).
  • If you're really stumped at how to write something in assembly, try coding it in C (it's easier hacking N64 games with C) and then look at the disassembly of the code afterwards to see how the compiler went and wrote it.
  • Don't you dare forget about floating point numbers and the floating registers!

You might want to take a look at my unfinished guide...: http://www.the-gcn.com/tutorials/article/4-ootmm-hacking-with-c-and-asm/

And there are a few example hacks written and C (and one incomplete ASM hack): http://www.the-gcn.com/topic/1262-jason777s-hack-ideas/

There's also another ASM hack I did: http://www.the-gcn.com/topic/1600-young-link-using-the-bow/

  • Like 1
Link to comment
Share on other sites

  • 0

Once I have some more free time and access to a better suited computer, I'll start on what you've suggested, and eventually get around to trying out your tutorial. Thanks much for the help!

 

I do have a few questions, however, if you'd be able to answer them. First off, isn't ASM used with C/C++ to code for most Nintendo home consoles? And isn't ASM used for the most part to assign certain parts of C/C++ to different registers for data management?

Link to comment
Share on other sites

  • 0

I do have a few questions, however, if you'd be able to answer them. First off, isn't ASM used with C/C++ to code for most Nintendo home consoles? And isn't ASM used for the most part to assign certain parts of C/C++ to different registers for data management?

 

Almost, but not quite. Assembly instructions are instructions that the processor actually understands with no further modification. For example, the N64 processor knows what to do if you hand it 0x03E00008, which is just the encoded form of "JR RA". C/C++ is a step above that, you give instructions that might result in many assembly instructions. Like

 

area = (base * height) / 2;

 

A compiler will take this statement and might turn it into something like

 

MULT T2, T0, T1 ; (Assuming that T0 and T1 have the values of base and height, multiply them and store the result in T2)

ADDIU T0, R0, 2 ; (Set the value of T0 to 2 by adding it with 0)

DIV T2, T0 ; (divide base * height which is in T2 by 2)

MFLO T0 ; (Move the result from LO to T0)

SH T0, (address of your area variable in memory) ; store it in RAM

 

This is just a rough example of what it might do, and then it would take those instructions and assemble them (which is basically putting them in a binary form, like turning JR RA into 0x03E00008) and then the processor knows how to carry out those instructions.

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.