80x86 16位asm:lea cx,[cx * 8 + cx]在NASM上导致错误(编译.com文件) [英] 80x86 16-bit asm: lea cx, [cx*8+cx] causes error on NASM (compiling .com file)

查看:101
本文介绍了80x86 16位asm:lea cx,[cx * 8 + cx]在NASM上导致错误(编译.com文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NASM给出的错误(尽管我的操作系统正常)是无效的有效地址".

The error NASM gives (despite my working OS) is "invalid effective address".

现在,我已经看到了许多使用LEA的示例,我认为我做对了,但是我的NASM不喜欢它.我尝试了lea cx, [cx+9],它起作用了; lea cx, [bx+cx]没有.

Now I've seen many examples of how to use LEA and I think I got it right but yet my NASM dislikes it. I tried lea cx, [cx+9] and it worked; lea cx, [bx+cx] didn't.

现在,如果我将寄存器扩展到32位(即lea ecx, [ecx*8+ecx]),一切都会好起来,但是我只能使用16位和8位寄存器.

Now if I extended my registers to 32-bits (i.e. lea ecx, [ecx*8+ecx]) everything would be well but i am restricted to use 16- and 8-bit registers only.

在这儿有没有什么知识渊博的人可以向我解释为什么我的汇编器不会让我以我应该使用的方式使用lea?

Is here anyone so knowledgeable who could explain me WHY my assembler doesn't let me use lea the way I supposed it should be used?

推荐答案

这是因为[bx+cx]在16位x86上的任何寻址模式下均无效,请参见此

This is because [bx+cx] isn't valid in any addressing mode on 16-bit x86, see this site for more info.

lea cx, [bx+di]lea cx, [bx+si]应该可以工作.

如果代码将在386或更高版本上以16位模式运行,则可以使用lea cx, [ecx + 9](地址大小前缀,但仍为16位操作数大小).

If your code will run on 386 or later in 16bit mode, you can use lea cx, [ecx + 9] (address-size prefix but still 16bit operand-size).

另请参见有关x86寻址模式(主要讨论32/64位寻址模式)和标签Wiki.

See also this Q&A on x86 addressing modes (mostly discussing 32/64bit addressing modes, and the x86 tag wiki.

这篇关于80x86 16位asm:lea cx,[cx * 8 + cx]在NASM上导致错误(编译.com文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆