Tuesday, January 24, 2012

General information about computers

So last post I explained how to get a working environment up for Windows 7 and general info for other OS's.
This time I'm going to be going over some of the theory required about computers.



Binary
As you may know all programs are eventually compiled to 1's and 0's, this is called binary.

Binary is based on the base 2 numerical system. Sounds scary ae? Well its not really.
Decimal which is what we use in daily life 0-9 is base 10 as it has 10 different digits we can use.
But in base 2 we only have 2, 1 and 0.

To convert to binary we use something called mod.
For those that wish to learn this the algarithym is:

   number -
   (
   number / 2
   round down
   * 2
    )

For binary it is either 1 or 0 as thats all that it can be.
You continue using mod till the resulting number is 0 or 1.

Example:
Change 17 decimal to binary
)17
2)17(1    17/2=8.5, 8.5 rounded down 8, 8 * 2 = 16, 17 - 16 = 1
2)8(0      8/2=4, 4 rounded down 4, 4 * 2 = 8, 8 - 8 = 0
2)4(0      4/2=2, 2 rounded down 2, 2 * 2 = 4, 4 - 4 = 0
2)2(0      2/2=1, 1 rounded down 1, 1 * 2 = 2, 2 - 2 = 0
2)1(1      1/2=0.5, 0.5 rounded down 0, 0 * 2 = 0, 1 - 0 = 1
2)0(0 Done..

Where the number on the left ) is the number to divide by (base), the number in middle of ) and ( is the last number after rounding down and the number after ( is the remainder.
So the binary version of 17 is 010001.
As we are working with computers.. good practice is to make it 8 digits long a byte.
We can do this by adding 0's to the front 00010001.

Now to reverse it
First remove all the padding 0's in this case the first three 0's.

(17
2)1(8    2*8=16, 16+1=17
2)0(4    2*4=8, 8+0=8
2)0(2    2*2=4, 4+0=4
2)0(1    2*1=2, 2+0=2
2)1(0    2*0=0, 0+1=1

Where the number on the left ) is the number to divide by (base), the number in the middle is the number from binary. These two are written out first not as you go.
The last number of the right of ( is the previous number calculated.
If you wish to add the padding 0's in you can but 2*0=0, 0+0=0 is a waste of time.

Octal and Hex based numeral systems (8 and 16)
Octal is base 8 this means you have numbers 0-7 inclusive.
Hex is base 16 which means you have number 0-9 but also another 6 so here is the problem how do we write that with no symbols to do it?
We use A-F to represent them.
So we have 0-F for hex.

The previous algorithms I showed above will still work but its really just a minor change from 2 to 8, 16.

CPU's (central processing unit)
CPU's currently are based on Intel's 8086 CPU from the 80's.
It may be old but it is still a good bases for our current CPU's.

CPU's have many different sub components but the key parts you must know of is that there is 2 different kinds of computation units inside it, the ALU (arithmetic logic unit) and FPU (floating point unit).
The ALU is used mainly for whole numbers and its what its designed for. The FPU is designed for well non whole numbers with a decimal point.
The next 2 parts is the instruction set L1 cache and data set L1 cache.
These store the data and the instructions on what to do.
The last part that is crucial for knowing about is the registers they are internal memory of the CPU for during computation of a cycle. Some have the maximum size which if its 32bit then they can contain ~ 4 bytes but not all are than size can be as small as a byte depends on the cpu.
I am not detailing about 64 bit here on this blog much as everything will still work fine on 64bit but it'll complicate things for a new beginner like myself in distinguishing and remembering more types of registers.

Instruction sets
The instruction set of each CPU will be different, but each compiler for assembly should handle this.
As long as you have the right version for your platform.

NASM which I explained to installed in previous post should be able to do so if you can install it.



A CPU is designed to compute simply things, like move x data to y or add x to y.
How ever the way its done is using only binary numbers in sets.
In assembly everything is very similar but just slightly higher to make it easier to understand for a human.
There is functions, segments to devide it up.

Hopefully that will be enough knowledge for now to understand how a program runs to be able to write an assembly application.

No comments:

Post a Comment