Compilation of D Code

Compilers for D language #

As of now, there are three D compilers to choose from:

  • dmd: the Digital Mars compiler

  • gdc: the D compiler of GCC

  • ldc: the D compiler that targets the LLVM compiler infrastructure.

In order to avoid the trouble of installing a compiler, we have already set up an environment for you on our platform so that you can easily learn and test your D programming language codes.

Compilation #

We have seen that the two tools most used in D programming are the text editor and the compiler. D programs are written in a text editor like the one we used in the previous lesson to write the code.

Although you don’t have to worry about the installation process, it is still a good idea to understand how the compilation works.

Machine code #

The brain of the computer is the microprocessor (or the CPU, short for central processing unit). e

Most CPU architectures use machine code specific to that particular architecture. These machine code instructions are determined under hardware constraints during the design stage of the architecture. At the lowest level, these machine code instructions are implemented as electrical signals. Because the ease of coding is not a primary consideration at this level, writing programs directly in the form of the machine code of the CPU is a very difficult task. These machine code instructions are special numbers, which represent various operations supported by the CPU.

Example #

For an imaginary 8-bit CPU, the numbers 4, 5, and 6 might be used to represent various operations as follows:

4 – Loading
5 – Storing
6 – Incrementing

Assuming that the leftmost 3 bits are the operation number and the rightmost 5 bits are the value that is used in that operation, a sample program in machine code for this CPU might look like the following:

Get hands-on with 1400+ tech skills courses.