Sunday, January 27, 2013

*Instruction Joke Here*

For part 2, let's discuss assembly instructions.  Note that I am assuming you have at least some programming knowledge. I will not be explaining high-level code.  This is an example of ASM:

ORR     R1, R1, R0,LSR R3

This is an ARM instruction.(as opposed to THUMB- we'll get to the difference soon)  It's also a fairly complex instruction.  It means this, basically:

r1 |= r0 >> r3  *or*  r1 = r1 | (r0 >> r3)

First of all, what IS an instruction?  It's a mnemonic device to assist humans in communicating directly with a CPU.  You see "ORR     R1, R1, R0,LSR R3", but the CPU sees "0xE1811330" / "b11100001100000010001001100110000".  So if you were going to write the code directly for the CPU to interpret it, you would need to write:

E1811330
E1A00210
E12FFF1E
etc..

instead of:

ORR     R1, R1, R0,LSR R3
MOV    R0, R0,LSL R2
BX        LR

So it's pretty easy to see why having an actual language that can be assembled by an assembler is much simpler and more convenient than simply writing every instruction out as hex or binary. 

I suppose that that begs the question: how do we get from the text assembly instructions to the code for the CPU to run?  We use an assembler.  It creates code from the mnemonic devices.  Since I have(and you should also have) DevkitARM installed, we have a copy of GAS(GNU Assembler) already installed that we could assemble code with.  Our other option is ASMtoARDS if we want an AR code ready to go.  Building something with the assembler is a project we'll get to later.  Right now we just want the very simple what, why, and how all of this works so that we can get to something more engaging. 

In the next post we'll have a look at how actual instructions function.

No comments:

Post a Comment