Open Watcom Inline assembly SEG and OFFSET operators

1.1k views Asked by At

Today, I have learned that the SEG operator in MASM by default returns the address of the GROUP and not the address of the SEGMENT of the expression in question, and that there are options and methods to override that.

Since I am currently doing a complex project in Open Watcom 1.9 / 16 bit DOS where C and assembly (inline and standalone) are mixed (actually, DOS is only needed for startup, then my own MINI-OS takes control), and since I know that WASM is somewhat MASM compatible, I have the following question:

When doing inline assembly and taking the segment of a variable, does the SEG operator return the GROUP or the SEGMENT which the variable is in?

Suppose there is a GROUP named MY_GROUP, a SEGMENT named MY_SEG which belongs to MY_GROUP, and a variable / label named MY_VAR which is placed in MY_SEG.

Then, if I do

_asm {
MOV AX, SEG MY_VAR
}

which value is loaded into AX? Is it the address of MY_GROUP or the address of MY_SEG (given that they are different)?

I did not find any command line switch which relates to that problem in inline assembly. I then tried the MASM syntax:

_asm {
MOV AX, SEG MY_GROUP:MY_VAR
MOV AX, SEG MY_SEG:MY_VAR
}

Both of the lines above lead to the following error: "Only segment or group label is allowed".

Please note that my problem only relates to inline assembly. Actually, I am using JWASM for the standalone assembly modules, and the syntax above works well and with the expected results there.

Could anybody tell me what the inline assembler does in this situation, and if there are means how I could control its respective behavior?

Thank you very much!

1

There are 1 answers

4
Ross Ridge On BEST ANSWER

I don't think there's any way to convince the OpenWatcom compiler to emit a group based segment relocation. Part of the problem is that there's no way to declare or define the group so that you can refer to it in the inline assembly.

However, it appears the OpenWatcom linker will ignore the fact that the relocations are segment based and instead use the group the segment belongs to as the base. So assuming you are using wlink then in your first example AX would be loaded with a segment value that points to the start of MY_GROUP. On the other hand, if you use Microsoft's segmented linker it then AX will contain a segment value that points to MY_SEG.