Pages: 1
Posted on 08-01-12, 06:50 pm (rev. 5 by  Dirbaio on 08-05-12, 11:32 pm)
Super Mario
( ͡° ͜ʖ ͡°)

Karma: 9979
Posts: 2073/4456
Since: 06-08-11

Understanding how the DS works


Some stuff you need to know about:

What ASM is: blahblahblah machine code blah compilers blah high/low level.

The RAM: It's used to store information. The RAM on the DS is 4MB, which is 4194304 bytes. Bytes can be organized into "halfwords" and "words": 2 bytes make a halfword, and 2 halftwords make a word.
The CPU can either read or write data to/from it. It can either read/write bytes, halfwords (2 bytes at a time) or words (4 bytes at a time). RAM can contain both data and code. (More on this later)

The CPU: The CPU is the part that makes the DS work. What it does is:
- Get one instruction from RAM
- Run it
- Go to the next instruction
- Repeat

The DS has two CPUs. There's a "main" CPU, the ARM9, and a "second" CPU, the ARM7. The ARM9 runs all of the game logic, and the ARM7 only controls stuff like wifi and sound. So all the interesting stuff happens in the ARM9, that's why most of the times, we only need to hack ARM9.

The CPU registers: A register is a memory location that holds a 32-bit number. The CPU has 16 registers, named from R0 to R15. Some registers have a special function, so they have a special name.
RegisterOther nameFunction
R13SPStack Pointer - Stores a pointer to the top of the stack.
R14LRLink Register
R15PCProgram Counter
The CPU stores the current instruction that's being executed in this register.

We'll talk later about them. For now, you just need to keep in mind that LR means exactly the same as R14.

Registers are important because the CPU can use them to do operations. The CPU can't use the RAM directly to do stuff like adding or substracting, so every time it needs to modify something in RAM it has to copy data from RAM to registers (called load) and copy data from registers to RAM (called store). Everything important happens in the registers.

Instructions

There are many types of instructions in ARM assembler. This section is not a complete manual for all of them, it's just a basic explanation so you get an idea. You can find the complete list of instructions at GBATek.

blahblahblah

Functions

calling convention
bx lr
push/pop

The Stack
Pages: 1