HLSL's, Cg and the RenderMonkey

Assembly Programming

For a moment, let's cast our mind back to the days when CPUs were in their infancy. Anyone who played with computers back when men were men and computer programmers didn't wash became very familiar with programming in "assembly language." For those of you who never went through the pain, assembly language is about as close as you can get to directly telling the CPU what to do, without using binary.

All computers work on 0s and 1s at the lowest level. The stream that tells the processor what to process is called the machine code, and generally looks something like this: 000100111010010110110101. Clearly this isn't the most intuitive way to program a processor, which is where assembly comes into play. You still program the instruction stream directly, instead using a more human readable interface. For example, moving a value from a location in memory to the local register on the processor would look something like this:

MOV AX, [BX],

which might translate to instruction 01110001, opcode 1010, opcode 1001 or 0111000110101001.

Using this sort of assembly language, you can build fairly complicated programs, but after a while, people got bored typing the same things over and over. And when that happened, they came up with higher-level languages. Basically, these add an extra layer of indirection on top of the assembly language, and allow an even more human readable "code." For example, imagine that the following assembly compares one value, and writes a second value depending on whether it's greater than five:

MOV AX, number // just imagine

CMP AX, 5
JG true
MOV CX, 2
JMP end
true:
MOV CX, 1
end:

In C, this would look more like:

if (number>5)

result = 1;
else
result = 2;

So in this case, C has allowed us to write some far more sensible code, which is just doing a comparison followed by setting a value. In the assembly code, the meaning has been lost if the programmer doesn't comment his or her code correctly, with the result that anyone maintaining the code has to trawl through the instructions, and work out what all the jumps are doing.

C has also allowed programmers to write their code once and then recompile it for multiple different platforms. This aspect of high level languages can make life a lot easier for programming teams writing software for multiple target platforms (i.e., XBox, Gamecube, PS2).