gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > The SWP instruction

#10720 - Lupin - Sat Sep 13, 2003 10:42 am

does anyone know how it works? I thought it just swaps 2 registers, but it somehow takes 3 arguments and needs these []-brackets (I even dunno where to place these brackets though)...

#10722 - Lupin - Sat Sep 13, 2003 11:13 am

...and what does ror do? I heard it should roll or rotate an value, but I couldn't imagine what this could mean

#10723 - momo - Sat Sep 13, 2003 12:52 pm

Swap:

swp Rd,Rm,[Rn]

does this:

Rd=[Rn] ;ldr Rd,[Rn]
[Rn]=Rm ;str Rm,[Rn]

its a load&store in one, its designed for making Software-Semaphores (unbreakable read/write).

The ror is a Roll Right, its means that the Bits rotated (Right out -> Left in). Example

$1234abcd ror 4 = $d1234abc
$12345678 ror 16 = $56781234

#10726 - Lupin - Sat Sep 13, 2003 1:04 pm

thx a lot momo! (hey, I'm from germany too, nice to see another ger here ^^)