Sunday, July 15, 2007
Bungie Day!
Monday, July 9, 2007
Modifing the size of your integer value
movw %ax, %bx
This should not be done because you can not be certain that the upper part of the EBX register is zeroed out ahead of time. To do this you should first zero out the EBX (destination) and then move your intended value there.
movl $0, %ebx
movw %ax, %bx
Intel provides another instruction that can do this with one instruction, movzx. It takes a source (a register or memory location) and converts to a larger size (register only) destination.
movl $300, %ecx
movzx %cl, %ebx
Just thought this was interesting.
Saturday, July 7, 2007
Under the C++ covers....literally
Studies on Assembly: (get the cpu vendor id info)
#cpuid - program to get the processor vendor id .section .data output: .ascii "Processor Vendor ID is 'xxxxxxxxxxxx'\n" .section .text .globl _start _start: movl $0, %eax cpuid movl $output, %edi movl %ebx, 28(%edi) movl %edx, 32(%edi) movl %ecx, 36(%edi) movl $4, %eax movl $1, %ebx movl $output, %ecx movl $42, %edx int $0x80 movl $1, %eax movl $0, %ebx int $0x80 |
This is a pretty simple assembly program. In the .data section there is a output label (think variable) defined. The .ascii is the "type" of data. In this case it means store ASCII string. The x's are placeholders for the real value coming later. The space for this data is reserved at compile time. The next section, .text, is where the instructions are stored for the program. The first instructions are to load the register EAX with a value of zero (literal). The next instruction is cpuid, which instructs the processor to get the id we are after. The zero value in EAX defines the CPUID output option. After the CPUID instruction is run, we must collect the result which will be in 3 output registers. The first instruction here (movl $output, $edi) creates a pointer from the output label to a register (EDI). Next we create pointers from the other 3 registers to the appropriate section of the EDI register. Now that all the results have been coorelated we can output the response. This program is using a Linux system call (int $0x80) to access the console from the kernel. This is a software interrupt (with the value 0x80). The EAX register will hold the specific instruction that will be executed when we make this interrupt. The EBX will hold the exit code that is given when the program exits. The ECX will hold the actual output (movl $output, %ecx). And the EDX register will hold the length of the string. Thats pretty much it. I will be posting more as my study of C++ and assembly continues.
Wednesday, July 4, 2007
Torque X for XNA creators (FREE!)

Friday, June 29, 2007
Size matters?

Thursday, June 21, 2007
Compressing Textures.....the DirectX way
Consider the following gradient:

If you were required to store this in a texture, you would end up having to store hunderds of RGB values to represent it If you instead stored say 2 colors (the ends) you perform linear interpolation to get the remaining colors and you have are only storing to values. A crude calculation to do just that is here:
Color_Gradient = (Color2 - Color1) / (GradientWidth - 1);}
for(i=0; i <>{SetPixelColor(i, 0, Color1 + (Color_Gradient * i));
This is roughly how DirectX can compress textures resulting in massive savings. Of course on a big texture you will probably have more than 2 colors and a simple bar object, so DirectX will partition the texture into a 4 x 4 matrix and based on the Texture Compression state chosen, will use either 1 or 2 of these grids (one for RGB and one for ALPHA) or just one and two RGB color values. The specifics of how the interpolation is performed again is dictated by the state of the Texture Compression chosen. More to come on this..
Sunday, June 17, 2007
Binary Serialization in .NET
SERIALIZE:
FileStream fStream = new FileStream(ConfigurationManager.AppSettings[1].ToString(), FileMode.Open); BinaryFormatter bin = new BinaryFormatter(); htObject = bin.Deserialize(fStream) as Hashtable; |
DESERIALIZE:
Stream binstream = File.OpenWrite(ConfigurationManager.AppSettings[1].ToString()); BinaryFormatter binFmtr = new BinaryFormatter(); binFmtr.Serialize(binstream, m_hashTable); binstream.Close(); |
This can be useful in XNA programming. More C++ for DirectX9 posts will be coming next week.