Simplest instructions

How does computer do something, if it understands only bits or threads of bits(e.g. 01001101010101001101010...)?
Ok, people decided to make computer understand commands(or opcode instructons...). It sees some sequence of bits as a command and manipulating these commands we can do just everything...
Read strings, calculate, format disks, read from ports and to ports, produce sound... The possibilities are immense!
Now, closer to the point. The most widely used instructions are:

MOV dest,source
Ok, for example mov a,b is equal to a=b
There are different ways mov can be used, which can be used:

  1. mov memory,reg, where memory is some value in memory and b is a register, containing immediate value
  2. mov reg,reg, where both are register containing some numbers
  3. mov reg,memory, where memory is some value in memory

Now, there were some new words here, like:

  1. Register - some container in a CPU, which can contain values. Access to the register is much faster than to any part of memory
  2. Immediate Value - a value, that isn't an address, just a value, e.g. in I have 2 apples 2 is an immediate value

add value,value
There are different ways to use this one, too:

  1. add reg1,reg2 - equal to reg1 = reg1 + reg2
  2. add reg,memory - equal to reg = reg + memory, memory is a value stored in memory
  3. add memory,reg - mostly the same, but here memory = reg + memory
  4. add reg,constant - reg = reg + constant
  5. add memory,constant - memory = memory + constant

Ok, now you do know some instructions, let's get closer to reality and to real computers.
Your CPU operates several types of registers. Now we'll examine general purpose registers:

  1. AX - an accumulative register, mostly used to save the result of calculations or contain the return value of a function
  2. BX - a register used to point to elements in an array(yes, there are arrays in asm)
  3. CX - just a count register, used in loops
  4. DX - used as a pointer to data in memory

Yes, all of them can be surely used to contain any values, but these are their special uses.

Example

Let's look at a small example, using all the instructions we have learned...

    mov ax,0
    add ax,F                 
ax = F
    mov bx,[0123]       
bx contains a value, which was in memory at address 123
    sub ax,bx               
ax = ax - bx

Exercise

Ok, what can you do?
Let's suppose we have a value AF at address 723 in memory. And we have ax=65,bx=6BE. How can we have ax=AF, using all these registers and memory? You can't add constants!

P.S. There are always answers. You just need to look for them!