I'm not 100% sure about the inner workings of various assemblers and processors, but I'm attempting as best as I can to explain, how I understand it
Let's say the machine instructions to perform a map transition / warp is some value, for example AC
.
Let's say, this instruction takes a value to decide where to warp the player. For example, the final boss room has value C8
.
So if you tell your game to call the routine to execute AC C8
, it knows that it should teleport the player to the final boss.
Now, assume you have some inventory mechanism that saves items by their id. A bomb has id C8
and a stick has id AC
.
Assume the data for the inventory is laid out sequentially, so having a stick first and then a bomb is represented as AC C8
as well.
Now "all you need to do" is to trick the program into jumping to a wrong location while it tries to execute some kind of action. This is usually done by the "program counter" which points to the address of the instruction to execute.
If you manage to manipulate the program counter to point to the start of your inventory instead of the address it normally should point to, the program will now read the data from your inventory, but treats it as executable code instead. So since your inventory contains "stick, bomb" the data that will be read is AC C8
, which causes the program to warp you to the boss room now.
I think something like this is usually achieved by corrupting parts of the memory or somthing similar. The section of memory that is corrupted contains "nonsensical" data now, but can still be executed.
I'd say, a good example of how all of this can be exploited is shown here: How to beat Pokemon Yellow in 0:00