MASM
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello.
MASM can be obtained by downloading the Visual Studio Processor Pack (you must have either VS Service Pack 4 or 5 installed first): NB: Visual Studio Service Pack 6 is not compatible with the processor pack
[edit] MASM And Games ProgrammingVery few games nowadays are written entirely in assembly (the main exception being older consoles such as the Sega Genesis, NES and SNES). However, it is still used where optimisation is required in a higher-level language such as C or C++. One can program either a small section of assembly 'embedded' into the high level language, or a whole routine seperately linked into the final program. [edit] Inline AssemblyWhen assembly is written inside another, higher level language, it is said to be inline, mainly because any variables in scope at the time are also in the scope of the assembly. Here are some examples, for both Microsoft Visual Studio 6 and GCC.
// Visual Studio 6
#include <iostream>
int main (int argc, char* argv[])
{
int a = 10;
int b = 10;
int result;
__asm mov eax, a
__asm add b, eax
__asm mov result, eax
std::cout << "Answer: " << result << std::endl;
return 0;
}
// GCC (G++)
#include <iostream>
int main (int argc, char* argv[])
{
int a = 10;
int b = 10;
int result;
asm ("movl %2, %%eax;
addl %%eax, %1;
movl %%eax, %0"
:"=r"(result)
:"r"(a), "r"(b)
:"%eax");
std::cout << "Answer: " << result << std::endl;
return 0;
}
[edit] External RoutinesWhere larger blocks of assembly are needed, it is common to write them in a seperate assembly file which is assembled externally, and the resulting object file linked into the final executable or library. These routines need to be declared as 'extern' in C/C++, and 'global' (Intel syntax) or '.globl' ( AT&T syntax) in the corresponding assembly file. |


