chevron_left chevron_right
Login Register invert_colors photo_library
Thread Rating:
  • 0 Vote(s) - 0 Average


filter_list Tutorial CYFA - Creating Your First Assembler - Branches and Conditionals
Author
Message
CYFA - Creating Your First Assembler - Branches and Conditionals #1
Welcome to part 5 of the CYFA series! (If you haven't read the first 4 parts, you can find a list of them here).

This will be the last of the boring memorization parts, at least for now. With the addition of this we will have covered all of the reference material we need to start working on code and theory! Alright, so what are we going to cover in this part? Well, firstly we'll be looking at branches. These are the equivalent of a jump for you Intel fanboys. After we dig through branches we'll finally loop back around and cover those condition fields that are at the start of every instruction. Let's get into it.

The branch format:
[Image: gF89NEr.png]

Ok, so this one looks REALLY simple, and it is! Let's look at it backwards, first we see the offset. This field is probably the most complicated field in the ARM processor, a lot goes on with it. This is the only instruction-based field that is a signed integer. It's a 24-bit 2's compliment signed offset. When this instruction is executed, this offset is sign extended (if you don't understand 2's compliment and sign extension, you should google that soon) to 32-bits, and then added to the CURRENT PC register. This means that this value is RELATIVE to the current instruction. ARM does not contain an instruction to jump to an absolute address in memory (though there is a way to do it).

Ok, so with that out of the way, let's have a look at the Link bit. This is confusing to many C++ programmers (where branch and jump both mean goto), and even for intel programmers. With ARM, there are not separate instructions for jump and call, they are both branch. With ARM, when you want to call (rather than jump), you set the link bit, which will set the value in R14 to the instruction after the branch, and then perform the branch. Likewise, ARM does not have a ret instruction, but rather you would branch (without link) to R14.



Ok, I knew that would be the  fastest out of all of them to explain, and it was, so now let's go ahead and take a look at that condition field. It is a 4-bit field, meaning that we have 16 conditions. Don't get confused though, this is not an integer, don't write it as "210", it doesn't hold a number.

This is going to be relatively easy to explain to you, I'm just going to drop a table here for you to look at.
[Image: DODrpA7.png]

I apologize for the low quality of this image, I snagged it from another source, and it's small.

The most common condition code you will come across is 0xFE (AL). This one is implicit on every instruction, so if no code is specified, you will put this down.
After that, there is 0xFF (NV). You may wonder why they even included this value, it seems useless right? Not really. This value is really useful when you're writing polymorphic code, you can comment out large portions of code without losing the instructions under them! This also will come in handy when we get to writing our assembler. If the user enters in NOP, we can just set the NV code on whatever the last instruction we just wrote was, and write it again without doing any slow memory tasks.,

For our assembler, we probably won't hit hard on overflow (V-bit) or carry (C-bit) stuff, so you can go ahead and ignore the following:
Code:
PL. VS. VC. CS, CC
We will use instructions that use both C and V (unsigned integer comparisons) though.



Alright, so this one was VERY sort, and I'm sorry about that, but I wanted to make sure I went through the foundations stuff very slowly so that you wouldn't skim any part of it. All of this stuff is critical to being able to do the next part, where we will start writing code!

Again, I judge interest by how many replies these threads get. If I get loads of replies, I write these faster. If I get little or no replies, either the series dies or I wait a week before writing the next part (which is what happened this time).
Please reply to this.
(This post was last modified: 10-25-2017, 06:28 PM by phyrrus9.)
I will keep that list up to date at all times. Check often for new materials!

[+] 1 user Likes phyrrus9's post
Reply

RE: CYFA - Creating Your First Assembler - Branches and Conditionals #2
Thanks for the information. Pls upload more

Reply

RE: CYFA - Creating Your First Assembler - Branches and Conditionals #3
Bumping this to try and bring life back into this series.. Please, somebody respond to tell me you're actually reading these
I will keep that list up to date at all times. Check often for new materials!

Reply

RE: CYFA - Creating Your First Assembler - Branches and Conditionals #4
(11-10-2017, 08:58 AM)phyrrus9 Wrote: Bumping this to try and bring life back into this series.. Please, somebody respond to tell me you're actually reading these

Thanks for bumping this, as I never really saw any of them! I will save all of these.

P.S. 600th post!!! WOOP WOOP! Cool
I shorten URL's using goo.gl to track clicks.

Reply






Users browsing this thread: 1 Guest(s)