## Thursday, August 1, 2013

### Loop De Loop

adding 1 + 2 + 3 + 4 + 5 + 6 + 7 up to a really big number like 100, first talk about adding 1 to 5, but then you can change the 5 to a 100

inc
cmp
jl
jle

63
multiple ways to write the same program

talk about the problems that you get when you put the inc between the cmp and the jl

Write blog post down here:

Have you ever wondered what you would get if you added 1+2+3+4  etc.? Well if you have this should be a good learning experience. First you need to put a 0 in eax, then you need to put a 1 in ebx. Then you add them together and after you do that you have two choices you can move the answer into another register and put a 2 in eax and a 3 in ebx and add them together and then add that to the answer and keep moving the numbers in eax and ebx up one time and write tons of code until you reach the number you want to go to, or you can take the easy way that takes a little bit more learning but it will save you a ton of headache if you do it.

The easy way has a lot to do with something called loops. A loop is when you do little bit of code that if repeated will make a good program and that's where the little bit of learning comes in. The first thing you need to know about if you want to take the easy way is cmp which is compare. Now cmp is when you put a number in a certain piece of ram, or register and use it as a counter. To count you can do a little piece of code called inc which means increment. When you inc ram or a register it adds one to that ram or register.
So  when you inc the piece of ram or register it gets bigger and when it gets to the number that you are counting to you are done, but the bit of magic that makes the program start all over again and completely save the headache there is one more thing.

The final piece of the puzzle lies in a little piece of code called jle. Now jl stands for jump less than or equal to that means if the digit in the counter is less than or equal to lets say 5 then go back to again. What I mean by again is you set a point in the program that you want to start over from. I like to call it again.

mov eax,0
mov ebx,1
again: