Open Watcom Inline assembly SEG and OFFSET operators

爱⌒轻易说出口 提交于 2019-12-23 02:49:20

问题


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:


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.



来源:https://stackoverflow.com/questions/30803553/open-watcom-inline-assembly-seg-and-offset-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!