# Using the OpenWatcom Assembler with 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
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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8234093,"math_prob":0.7840759,"size":2066,"snap":"2023-40-2023-50","text_gpt3_token_len":563,"char_repetition_ratio":0.09408341,"word_repetition_ratio":0.0,"special_character_ratio":0.26476282,"punctuation_ratio":0.13963965,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9672281,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-01T15:12:33Z\",\"WARC-Record-ID\":\"<urn:uuid:a0717056-8655-43f6-a036-ad65c52bcf6d>\",\"Content-Length\":\"43087\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f105cc4a-a326-4473-8767-cc8e584f2ee2>\",\"WARC-Concurrent-To\":\"<urn:uuid:de1326ff-0464-426f-bec1-e6ff525ce595>\",\"WARC-IP-Address\":\"185.227.110.91\",\"WARC-Target-URI\":\"http://www.myrkraverk.com/blog/2018/04/using-the-openwatcom-assembler-with-jam/\",\"WARC-Payload-Digest\":\"sha1:EQOSEHT44KZBR2MAOOZV3KB4RQSZ7ZRJ\",\"WARC-Block-Digest\":\"sha1:YBV4C2IOFICXF2VX57U7YGF52D54EIBB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510903.85_warc_CC-MAIN-20231001141548-20231001171548-00774.warc.gz\"}"}