DOS 上的 NASM(Intel 8086):有效地址无效
我正在使用 Bochs 编写 DOS 代码。我正在使用 NASM
编译程序 假设我有以下代码:
[BITS 16]
SEGMENT code
..start:
mov ax, data
mov ds, ax
mov bx, msg
mov al, byte [bx]
int 21h
SEGMENT data
msg DB "teststring", 00h
线上抱怨
mov al, byte [bx]
为什么 nasm在 无效的有效地址
?如果我不使用bx,而是使用si注册表,则程序会按预期编译一个作品,在中加载t的ascii值等。
这是为什么呢?
编辑:发现我无法使用 BX 进行索引。
如果我想加载数据段的确定部分中指向的内容,您可以执行以下操作:
mov ax, data
mov ds, ax
mov si, msg
mov al, byte [si] ; Loading first char
inc si
mov al, byte [si] ; Loading second char
如果我想保持 si 指向字符串的开头,那么我可以使用 BX offset:
mov al, byte [si + bx]
甚至
mov al, byte [si + n] ; where n is an integer value
但据我了解,也可以使用 bx,所以问题仍然存在。
I am writing code for DOS using Bochs. I am compiling the program using NASM
Lets suppose i have the following code:
[BITS 16]
SEGMENT code
..start:
mov ax, data
mov ds, ax
mov bx, msg
mov al, byte [bx]
int 21h
SEGMENT data
msg DB "teststring", 00h
Why is it that nasm complains on the line:
mov al, byte [bx]
of invalid effective address?
If instead of using bx i use the si registry, the program compiles an works as supposed, loading the ascii value of t in al.
Why is it?
EDIT: Found that I can't use BX for indexing.
If I wanted to load what's pointed in a determined part of the data segment, you could do the following:
mov ax, data
mov ds, ax
mov si, msg
mov al, byte [si] ; Loading first char
inc si
mov al, byte [si] ; Loading second char
If I wanted to keep si pointing to the start of the string, i could then use BX to be the offset:
mov al, byte [si + bx]
or even
mov al, byte [si + n] ; where n is an integer value
But to my understanding, bx could also be used, so the problem still resides.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您在问题中犯了不止一个错字:-) 首先,在 16 位模式下 [bp][bx][si][di] 都是有效的寻址模式。即使是旧的8086也可以使用[bx]作为有效地址。
由于 [dx] 不能在 16 位模式下使用,据我所知它需要在 32 位模式下运行。连同您
前面的
行,我假设您实际上写了“mov al, [dx]”,并且 nasm 正确地抱怨 [dx] 作为无效地址。所以,如果你的意思是,你发现你不能使用 [bx],那么你就错了 - 你发现你需要更加小心,不要将“d”拼写为“b”。
I think you made more than one typo in your question :-) First of, in 16 bit mode [bp][bx][si][di] are all valid addressing modes. Even the old 8086 can use [bx] as an effective address.
Where as [dx] can not be used in 16 bit mode, afaik it needs to be running in 32 bit mode. Together with your line
preceding
I assume you wrote in fact 'mov al, [dx]' and nasm is correctly complaining about [dx] as an invalid address. So if you meant, you found out you can't use [bx], you were wrong - you found out that you need to take more care in not misspelling "b" for "d".
您确定错误不在这一行吗?
也许你的意思是:
You sure the error is not on this line?
Perhaps you meant: