简体   繁体   English

打开Watcom内联汇编SEG和OFFSET运算符

[英]Open Watcom Inline assembly SEG and OFFSET operators

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. 今天,我了解到,默认情况下,MASM中的SEG运算符返回的是GROUP的地址,而不是所讨论表达式的SEGMENT的地址,并且有一些选项和方法可以覆盖它。

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: 由于我当前在Open Watcom 1.9 / 16位DOS中执行一个复杂的项目,其中C和程序集(内联和独立)混合使用(实际上,DOS仅在启动时才需要,然后由我自己的MINI-OS进行控制),并且由于我知道WASM在某种程度上与MASM兼容,我有以下问题:

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? 在进行内联汇编并获取变量的分段时,SEG操作员是否返回变量所在的GROUP或SEGMENT?

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. 假设有一个名为MY_GROUP的GROUP,一个属于MY_GROUP的名为MY_SEG的SEGMENT和一个位于MY_SEG中的名为MY_VAR的变量/标签。

Then, if I do 那我做的话

_asm {
MOV AX, SEG MY_VAR
}

which value is loaded into AX? 哪个值加载到AX中? Is it the address of MY_GROUP or the address of MY_SEG (given that they are different)? 是MY_GROUP的地址还是MY_SEG的地址(假设它们不同)?

I did not find any command line switch which relates to that problem in inline assembly. 我没有发现任何与内联汇编中的问题相关的命令行开关。 I then tried the MASM syntax: 然后,我尝试了MASM语法:

_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. 实际上,我将JWASM用于独立的程序集模块,并且上面的语法运行良好,并且在那里具有预期的结果。

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! 非常感谢你!

I don't think there's any way to convince the OpenWatcom compiler to emit a group based segment relocation. 我认为没有任何方法可以说服OpenWatcom编译器发出基于组的段重定位。 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. 但是,OpenWatcom链接器似乎将忽略重定位是基于段的事实,而是使用该段所属的组作为基础。 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. 因此,假设您使用的是wlink则在第一个示例中,AX将加载一个指向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. 另一方面,如果您使用Microsoft的分段链接器,则AX将包含指向MY_SEG的分段值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM