These tutorials focus mainly on OpenGL, Win32 programming and the ODE physics engine. OpenGL has moved on to great heights and I don't cover the newest features but cover all of the basic concepts you will need with working example programs.
Working with the Win32 API is a great way to get to the heart of Windows and is just as relevant today as ever before. Whereas ODE has been marginalized as hardware accelerated physics becomes more common.
Games and graphics utilities can be made quickly and easily using game engines like Unity so this and Linux development in general will be the focus of my next tutorials.
Assembly Theory Explained
BITs and BYTEs
To begin understanding how assembly works we have to know about BITS and BYTES.
Imagine that there are two islands out in the ocean and there is a person on each of the islands. Now they want to send messages or instructions to each other but all they can use is a wire connected to a light bulb at one end and a toggle switch at the other end (also imagine for now that one wire can make a circuit). The two people on the islands have extended the wire between the islands so that one person has the bulb end and the other person has the switch end. They have agreed that if the light is on that it means the person with the switch is out fishing and if the bulb is off that they are back.
This is the analogy for a single BIT, it can only be on or off. The two people could have agreed that on meant they were washing their hair and off meant that they were finished.
The problem with a single BIT is that it can only convey two instructions, so the two people extend another bulb, wire and switch between the islands and call the first wire BIT 0 and the second wire BIT 1.
The good news is that by using combinations of BIT 0 and BIT 1 they can now send four messages. For example, if both BITs are on then this could mean that the person at the switches end was fishing and both off meant that they were back without a fish. But if BIT 0 was on and BIT 1 was off then this meant that they had a fish and if BIT 0 was off and BIT 1 was on that this meant they had caught a fish and they were going to swim over and share it.
So they would have something like this:
BIT no. 1 0
off off = Back without a fish.
off on = Back with a fish.
on off = Back with a fish, I'm coming over.
on on = Gone fishing.
You can see that the more BITs that are used the more instructions that can be conveyed by using combinations of off and on for each BIT.
In computer terms a 0 is used to represent an off BIT and a 1 is used to represent an on BIT. So the people on the island would have:
BIT no. 1 0
0 0 = Back without a fish.
0 1 = Back with a fish.
1 0 = Back with a fish, I'm coming over.
1 1 = Gone fishing.
Also, in computers the instructions are not words or sentences but are numbers.
For example:
BIT no. 1 0
0 0 = 0
0 1 = 1
1 0 = 2
1 1 = 3
You may be wondering how they decided which number goes with each BIT combination. It is to do with the BIT number which describes the bits position. In this example, if I was to say to you "BIT 0" you would know that I was talking about the right most BIT and if I mentioned "BIT 1" you would know I was talking about the left most BIT. If a bit is on, it is assigned a value depending on its BIT number (position). This value is 2^(BIT no.) or 0 if the BIT is off.
For example:
BIT no. 1 0
0 + 0 = 0
0 + 2^0 = 1
2^1 + 0 = 2
2^1 + 2^0 = 3
( Note: any number to the power of 0 has a value of 1. )
In computers the instructions are generally made up of 8 BITs numbered 0-7.
For example:
The 8 BIT binary number 11010101 would be...
BIT no. 7 6 5 4 3 2 1 0
1 1 0 1 0 1 0 1 = 213
or
2^7 + 2^6 + 0 + 2^4 + 0 + 2^2 + 0 + 2^0 = 213
The easier way to remember each BITs value is to remember the powers.
For example:
(BIT value 128 64 32 16 8 4 2 1)
BIT no. 7 6 5 4 3 2 1 0
1 1 0 1 0 1 0 1 = 213
or
128 + 64 + 0 + 16 + 0 + 4 + 0 + 1 = 213
Using 8 BITs, 256 unique combinations can be made which means that the numbers 0-255 can be expressed.
For example:
00000000 = 0
00000001 = 1
00000010 = 2
"
"
11111111 = 255
A BYTE is another way of saying 8 BITs. So a BYTE may only have a value of between 0 and 255.
To convert a BYTE value into its BIT values (binary), start by subtracting the highest BIT value from the BYTE value. If you can (because the BYTE value was bigger than 128) you know that the high BIT is on. You then continue to subtract the next biggest BIT value from the remainder, and so on.
For example:
To convert the BYTE value 213 into its BIT values...
213 - 128 = 85 so BIT 7 is on... 1
85 - 64 = 21 so BIT 6 is on... 11
21 - 32 cant be done so BIT 5 is off... 110
21 - 16 = 5 so BIT 4 is on... 1101
5 - 8 cant be done so BIT 3 is off... 11010
5 - 4 = 1 so BIT 2 is on... 110101
1 - 2 cant be done so BIT 1 in off... 1101010
1 - 1 = 0 so BIT 0 is on... 11010101
To visualize computer memory, think of it as being a very long line of BITs. But to work and program with memory we have to know that these BITs are grouped into groups of 8 BITs (BYTES) for easier programming.
For example:
Memory may look like this:
11010101000101010110100111011110...
Which becomes:
11010101 00010101 01101001 11011110 ...
Which becomes:
213 21 105 222 ...
And is normally expressed in a top down manner with the lowest BYTE in memory being at the top:
213
21
105
222
.
.
Where a BYTE is positioned in memory is referred to as its memory address. The first BYTE is at memory address 0, the second BYTE is at memory address 1, and so on.
For example:
Address
0 213
1 21
2 105
3 222
4 .
5 .
. .
. .
That's enough on BITs and BYTEs for now. I'll discuss memory, addresses and the interesting things BITs and BYTEs can do in further chapters.