Quote:
Originally Posted by AkameTheBulbasaur
Thank you! I looked everywhere for that. I didn't want to use it willy-nilly without knowing who made it/who to give credit to.
|
You can probably tell if it's me depending on the word "linker" and how I assign variables using their direct address. Most people name "linker" something else and they use a .VAR or something for variables :D
Quote:
Originally Posted by Knight of Duty
Well, yesterday i tried to do something and realised i do not understand a few things, such as bit shifting and swi. Can anyone clarify those?
|
Bit shifting is just binary manipulation and swi are software interrupts. SWI commands can be read up on at gbatek, there's quite a few and the technical details are very important.
I reccomend you read ShinyQuagsire's tutorial if you're just starting off and want to learn about bit shifting. Once you've got a handle on that, you can come back and read the rest of this post.
Bit shifting is just a binary manipulation and works just as it does on paper. There are two types of possible shifts, a left shift and a right shift. The left shift takes the current value in binary form and appends a zero to it, it then removes the leading bit. The right shift takes the current value in binary form and prefix's a 0 to it and removes the trailing bit.
Keeping in mind registers can only hold 32 bits (4-bytes)
Code:
mov r0, #0x1
lsl r0, r0, #0x1
After the mov instruction r0 would contain "00000001" in hex (which in this case is also the binary representation). Doing that lsl r0, r0, #0x1 command, as I explained, would then yield "00000010" in binary or "00000002" in hex.
Lets try something a little more complicated.
Code:
mov r0, #0x10
lsr r0, r0, #0x2
Here r0 after the mov instruction would contain '00000010" in hex, or "00010000" in binary. Now if we apply the lsr on the binary form we remove two trailing bits and prefix two zeros. That would give us: "00000100" or 0x4 in hex.
You'll notice that I'm showing you 8 bit values for the binary representation of a register which is supposed to contain 32 bits (4 bytes). That's because I'm way too lazy to type all of those zeros, and it doesn't matter for the small values we used :D