Computing: DOS, OS/2 & Windows Programming

Using the RHIDE IDE to build 32-bit assembly programs.

In my FreeDOS tutorial 32-bit assembly programming using NASM and GCC, I show how to use NASM together with the GCC C compiler to build 32-bit protected mode programs on DOS. The tutorial describes how this build may be done in the DOS command line, running first NASM with the -coff option to create a 32-bit object file of the assembly source (object file compatible with the DJGPP environment), and second running GCC to compile the main C program, and linking the object file created together with the assembly object file (and C function dependencies). It also describes my custom batch script, that includes all settings needed to not only build 32-bit programs, but also 16-bit real mode, and 16-bit protected mode programs.

In another FreeDOS tutorial, Installing and running DJGPP (C, C++), I describe RHIDE as IDE for C/C++ development in a DJGPP environment. RHIDE includes support for other programming languages (in particular G77). It also includes syntax highlighting for assembly, and thanks to GNU Make, it offers an easy way to build mixed programming languages programs, in particular, 32-bit programs made of a GNU C main program, that calls subroutines coded as NASM source (the NASM routines themselves using the C function gets for input from the keyboard, and the C function printf for output to the screen).

The tutorial samples have been written and tested on FreeDOS 1.3 RC5; they should also work on other DOS platforms. The tutorial pre-supposes that you have installed NASM, as well as DJGPP, including GCC and RHIDE (and that both of these two installations are working all correctly).

As example let's take the sources hello4.c and hello4.asm of my NASM 32-bit tutorial.

Here is the code of hello4.c:

#include <stdio.h>
extern void sayhello(void);
int main(void) {
  sayhello();
  return 0;
}

And the code of hello4.asm:

[BITS 32]
[GLOBAL _sayhello]
[EXTERN _printf]

[SECTION .text]
_sayhello:
        push    ebp
        mov     ebp, esp
        push    dword hello
        push    dword fhello
        call    _printf
        mov     esp, ebp
        pop     ebp
        ret
[SECTION .data]
hello   db      'Hello, World!', 00h
fhello  db      '%s', 0Dh, 0Ah, 00h

Before running RHIDE, make sure that both your DJGPP and NASM binaries are in your PATH. Also make sure that the environment variable DJGPP is set. In the case, where you use your DJGPP files with both GCC and F77 (cf. my tutorial Installing and running Gnu Fortran), be sure that it's the C related files, that are actually set to be used!

I copied the C and assembly sources to my DJGPP development directory D:\Devel\DJGPP. Then (supposing that the correct DJGPP files are set to be used), in order to create a new RHIDE project, called hello4, I ran the following commands (%path0% is a custom environment variable on my system, set equal to %path% in my fdauto.bat file):

set path=c:\djgpp\bin;c:\nasm;%path%
set djgpp=c:\djgpp\djgpp.env
rhide hello4

In the RHIDE project window, use Add from the commands bar at the bottom of the page, to add the C and assembly sources to the project.

Using RHIDE with NASM 32-bit on FreeDOS: Adding the C and assembly sources to the RHIDE project

The screenshot below shows the source files, opened in RHIDE: On the left screenshot the C source hello4.c; on the right screenshot the assembly source hello4.asm.

Using RHIDE with NASM 32-bit on FreeDOS: C source file, opened in RHIDE
Using RHIDE with NASM 32-bit on FreeDOS: Assembly source file, opened in RHIDE

It's possible that there are other ways to do (?), but using GNU Make is certainly the easiest way to build a NASM 32-bit RHIDE project, made of a C and an assembly source file. To use Make, we'll have to create a Make file (in our case: hello4.mak), that will contain the build instructions for the project.

In RHIDE, choose File > New from the menu bar, and save the file as hello4.mak. Here are the commands, that I added to this file:

hello4.exe : hello4.c hello4.o ; gcc hello4.c -o hello4.exe hello4.o -v -Wall
hello4.o : hello4.asm ; nasm -f coff hello4.asm

In short: For both the object file to be created from the assembly source hello.asm and the executable to be created from the C source hello4.c plus the output of the assembler (hello4.o), add a line, containing the following:

  1. the target file name
  2. the source file name(s), separated from the target file name by a colon (:)
  3. the compiler/assembler command to be run, separated from the source file name(s) by a semicolon (;)
For further information concerning GNU Make, have a look at the GNU compiler collection documentation, or search the Internet.

RHIDE includes a command to make an executable using a Make file (menu command: Compile > Make). Unfortunately, using this command results in several errors during linkage.

Using RHIDE with NASM 32-bit on FreeDOS: Adding the C and assembly sources to the RHIDE project

I don't know what could be the cause of these errors. Some bad configuration of my RHIDE settings? Some other configuration problems? No idea! Anyway, this is not a big deal, because there is a simple work-around: Just run make.exe from the DOS command line, or (as we are working within RHIDE), run make.exe in a RHIDE DOS shell.

To do so, choose File > DOS Shell from the menu bar. Then, in the shell, run the Make command as follows:

make -f hello4.mak

The screenshot on the left shows the DOS shell at startup and the Make command ready to be executed. The screenshot on the right shows the last part of the build messages, including the one that confirms the successful creation of the executable hello4.exe.

Using RHIDE with NASM 32-bit on FreeDOS: Running make.exe in a DOS shell [1]
Using RHIDE with NASM 32-bit on FreeDOS: Running make.exe in a DOS shell [2]

Note: To quit the shell and return to RHIDE, use the exit command.

To terminate the tutorial, here is a screenshot showing all files of our hello4 project, as well as the successful execution of hello4.exe. The files hello4.gpr and hello4.gdt are RHIDE project files. The files hello4.c and hello4.asm are our C and assembly sources. The file hello4.mak is our Make file. The file hello4.o is the object file created by NASM, when assembling hello4.asm. And finally, hello4.exe is the executable (including everything needed to run the program – supposed that, on 16-bit systems, the 32-bit extender is present).

Using RHIDE with NASM 32-bit on FreeDOS: Files of a NASM 32-bit RHIDE project, and program execution

If you find this text helpful, please, support me and this website by signing my guestbook.