Category Archives: Jam

Using the OpenWatcom Assembler with Jam

I’ve previously covered the OS/2 port of Perforce Jam.

Here we’ll go over what it takes to make Jam know about the OpenWatcom assembler, Wasm.

First we can look at the Jambase file, in the source where we find the

actions As
{
$(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
}

and we see that Jam has a few variables related to assembler files.

The Jamfile

First, we tell Jam that our assembler is Wasm.

AS = wasm ;

Then we redefine the As actions to be

actions As
{
$(AS) -q $(ASFLAGS) $(ASHDRS) -fo=$(<) $(>)
}

where -fo=$(<) is the output file, and $(>) the input file. We could also have used the newer syntax, $(1) and $(2). The -q tells Wasm to operate quetly; it means we won’t see the copyright information every time we run Jam; only the nice As file.asm output.

Now, we can make use of these changes with

Main hello.exe : hello.c sum.asm ;

The Sources

The source files we mentioned above are hello.c and sum.asm.

Here is hello.c

  #include <stdio.h>

  int sum( int a, int b );

  int main( int argc, char *argv[] ) {

    printf( "Hello, %d.\n", sum( 3, 5 ) );
    return 0;
  }

And here is sum.asm

  .386
  .model flat
  .code
  PUBLIC sum_
  sum_ PROC
      add eax, edx
      ret
  sum_ ENDP
  END

These two files demonstrate how we can declare a function in C, and then define it in an assembly file. We are using the register calling convention of OpenWatcom. The first argument is in eax, the second in edx and the return value is again in eax. That means we don’t have to worry about stack manipulation at all, in a simple function like sum(). OpenWatcom appends _ to function names with the register convention, so we have to append it also in the .asm file.

With the above Jamfile, we just run

jam

and our demonstration program is built and linked properly for us.

Running the Demo

Now, when we run

hello

on the command line, we see

Hello, 8.

Final Words

This has been written as Jamfile demonstration, but it can also be viewed as a demonstration of the register calling in OpenWatcom.

Do you need professional help with OS/2? Write to johann@myrkraverk.com.