解决x86中mov指令的问题 [英] Addressing issue with mov instruction in x86

查看:157
本文介绍了解决x86中mov指令的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写在VGA显示器上打印字符的代码(在QEmu窗口中看到).这是我的代码:
(此文件为putInMemory.asm)

I am trying to write a code which prints a character on the VGA display (seen on QEmu window). Here is my code:
(This file is putInMemory.asm)

;Put the charcter in cx at the beginning of line number given by dx
printInMemory:
pusha
mov es, 0xb000
mov ax, 0x8000
mult:
cmp dx, 0x1
je done
add ax, 160
jmp mult
done:
mov [es:ax], cx
add ax, 1
mov [es:ax], 0x7
popa
ret

我想将寄存器cx中包含的ascii代码复制到内存位置0xb80a0,这是显示器中第二行的开始地址.这是代码:

I want to copy the ascii code contained in register cx to memory location 0xb80a0, which is the address of beginning of the 2nd line in the display. Here is the code:

[org 0x7c00]
mov cx, 'e'
mov dx, 0x2
call putInMemory
jmp $

%include "putInMemory.asm"

times 510-($-$$) db 0
dw 0xaa55

当我使用nasm汇编以上代码时,在第一个代码中出现以下错误:
putInMemory.asm:12:错误:有效地址无效
如何在mov指令中使用分段寻址?

When I assemble the above code using nasm, I get the following error in the first code:
putInMemory.asm:12: error: invalid effective address
How can I use segmented addressing in mov instruction?

推荐答案

以16位代码指定有效地址时,您不能使用ax(请参见名为带有16位地址的表格"英特尔软件开发人员手册中的"ModR/M字节" ).改用bxbpsidi.

You can't use ax when specifying an effective address in 16-bit code (see the table named "16-Bit Addressing Forms with the ModR/M Byte" in Intel's Software Developer's Manual). Use bx, bp, si or di instead.

这篇关于解决x86中mov指令的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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