# Chapter 7

### Multiplication

Lucky us, the GBA processor has several multiplication instructions. They are:
MUL, MLA, UMULL, UMLAL, SMULL, SMLAL. All of these can set the status flags with **S**. Also note that you can only use registers
with these instructions, and none of them use the shifter.

The MUL instruction is the most basic. It does a 32bit multiply with the format we've seen before:

`MUL DEST, OP1, OP2`

- DEST = OP1 * OP2. Note that a multiplication could generate a result bigger than 32bits.
With MUL, these bits are lost. Simple, eh?

The MLA instruction is similar to MUL, except it takes another operand. Take a look:

`MLA DEST, OP1, OP2, OP3`

- DEST = (OP1 * OP2) + OP3. That's right the first two are
multiplied, then the last is added. MLA stands for MuLtiply with Accumulate. Example:

`MLA r9, r0, r1, r2`

- r9 = (r0 * r1) + r2. Doesn't get any harder than that!

The UMULL and SMULL instructions do 32bit unsigned and signed multiplies respectively. The difference between these and
MUL, is that they allow for a 64bit result. The format looks like this:

`UMULL DEST(upper 32), DEST(lower 32), OP1, OP2`

- The first register takes the upper 32bits of the result, second, the lower.
The OP1 and OP2 registers are multiplied.

The UMLAL and SMLAL instructions are like 64bit versions of MLA. They do a multiply allowing for a 64bit result, then do a 64bit add with
the value made up of the destination registers. Examples:

`UMLAL r0, r1, r2, r3`

- r0 and r1 make up a 64bit value. r2 and r3 are multiplied together and the 64bit result is added to the 64bit value in r0/r1.
The result is put into r0 and r1.

I hope you all get that when I say "format" and you see DEST, OPx, etc... I mean that you can put any registers there. OP1, OP2, DEST, etc. aren't real registers. You probably knew that, but this is just to make sure.

I'd show you division here, but there aren't any division instructions in our CPU... *insert creepy music here*. Don't be afraid to use these instructions, unlike division, these are quite fast.

That's all for now, How about Chapter 8? Or the GBA ASM index?

Patater GBAGuy Mirror

Contact