Search code examples
assemblynaming-conventionsmasmrxdos

Function naming convention in RxDOS


In RxDOS source code, functions with the same name are differentiate with a numeric suffix like this:

RxDOS_WRITESTUB:
...
RxDOS_WRITESTUB_06:
...
RxDOS_WRITESTUB_10:
...

Why is it that way?


Solution

  • It appears to be a crude way of implementing scoped labels. The source is meant to be compiled with MASM 5.1 which doesn't support function scoped labeled by default. All the labels defined in a function (eg. a PROC/ENDP block) are visible outside of the function so care needed be taken in order to not define a label with the same name in two different functions.

    The convention used here is to not to use MASM's PROC/ENDP blocks to define functions, and simply use an ordinary label to mark the start of a function. Labels within the function are formed by appending a number to the function name. So RxDOS_WRITESTUB is the name of a function, while RxDOS_WRITESTUB_06 is the name of a label within that function. The later label is only meant to be referenced by code within the function.

    I wouldn't recommend following the convention in your own code. MASM has supported function scoped labels by default since MASM 6.0, which was released in 1991. A better convention would be to write code something like following:

    RxDOS_WRITESTUB PROC
        ...
    loop_args:
        ...
    found_switchchar:
        ...
    RxDOS_WRITESTUB ENDP
    

    Note how instead of numbers I've given more descriptive names to the function local labels.