Moving from assembly to high-level programming languages
Developers mostly don’t write in assembly. Instead, they write in higher-level languages, such as C or C++, and the compiler converts this high-level code into a low-level representation in assembly language. In this section, we will look at different code blocks represented in the assembly.
Arithmetic statements
Let’s look at different C statements and how they are represented in the assembly. We will use Intel IA-32 for this example. The same concept applies to other assembly languages as well:
- X = 50 (assuming 0x00010000 is the address of the X variable in memory):
mov eax, 50 mov dword ptr [00010000h], eax
- X = Y + 50 (assuming 0x00010000 represents X and 0x00020000 represents Y):
mov eax, dword ptr [00020000h] add eax, 50 mov dword ptr [00010000h], eax
- X = Y + (50 * 2):
mov eax, dword ptr [00020000h] push eax ; save Y for now mov eax, 50 ; do the multiplication first...