请教 简单 AT&T 各寻址方式指令写法

mzlogin 2008-11-29 03:30:58
我才开始学汇编,
是用的GAS汇编器所以是AT&T风格语法的。
我改写一个Intel风格的指令:
mov ds:[0020h],bx
为以下几种方式编译时都能通过,但执行却出现“段错误”
movw %bx,%ds:(0x0020)
movw %bx,$ds:(0x0020)
movw %bx,(0x0020)
把()换成[ ]则编译都通不过,
显示错误
bad memory operand `[0x0020]'

请教这样的应该怎样改写?
如有高手能为我简单讲下各种寻址方式的指令在AT&T风格下的具体写法
感激不尽!!!
这个东东困扰我几天了!
...全文
239 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzlogin 2008-12-04
  • 打赏
  • 举报
回复
那我应该怎样写呢?
这个……是实模式与保护模式的问题吗?
  • 打赏
  • 举报
回复
windows、Linux都是有存储保护的,不象DOS,你访问0020h当然会有问题。
mzlogin 2008-11-29
  • 打赏
  • 举报
回复
回2楼:
嗯不是DOS程序,
我是在Linux下。
mzlogin 2008-11-29
  • 打赏
  • 举报
回复
出现错误后
info registers
各寄存器状况为:

(gdb) info registers
eax 0x3ff 1023
ecx 0x8 8
edx 0x0 0
ebx 0x3ff 1023
esp 0xbfae1a30 0xbfae1a30
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x8048060 0x8048060 <_start+12>
eflags 0x210292 2163346
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x0 0
(gdb)
mzlogin 2008-11-29
  • 打赏
  • 举报
回复
回1楼:
是的,能确定。
我的源程序是:

.text
.global _start

_start:
nop
movb $0x08,%bl
movb %bl,%cl
movw $0x03ff,%ax
movw %ax,%bx
movw %bx,%ds:(0x0020)

movl $0,%ebx
movl $1,%eax
int $0x80


下面是我的调试过程:

[mzlogin@localhost Desktop]$ make
as -g -o 1.o 1.s
ld -o 1 1.o
[mzlogin@localhost Desktop]$ gdb 1
GNU gdb Everest Linux (6.4-1)
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) l
1 .text
2 .global _start
3
4 _start:
5 nop
6 movb $0x08,%bl
7 movb %bl,%cl
8 movw $0x03ff,%ax
9 movw %ax,%bx
10 movw %bx,%ds:(0x0020)
(gdb) b * _start+1
Breakpoint 1 at 0x8048055: file 1.s, line 6.
(gdb) r
Starting program: /home/mzlogin/Desktop/1

Breakpoint 1, _start () at 1.s:6
6 movb $0x08,%bl
Current language: auto; currently asm
(gdb) n
_start () at 1.s:7
7 movb %bl,%cl
(gdb) n
_start () at 1.s:8
8 movw $0x03ff,%ax
(gdb) n
_start () at 1.s:9
9 movw %ax,%bx
(gdb) n
_start () at 1.s:10
10 movw %bx,%ds:(0x0020)
(gdb) info registers
eax 0x3ff 1023
ecx 0x8 8
edx 0x0 0
ebx 0x3ff 1023
esp 0xbfae1a30 0xbfae1a30
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0x8048060 0x8048060 <_start+12>
eflags 0x200292 2097810
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x0 0
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
_start () at 1.s:10
10 movw %bx,%ds:(0x0020)
(gdb)
  • 打赏
  • 举报
回复
你生成的不是DOS程序吧。
killbug2004 2008-11-29
  • 打赏
  • 举报
回复
执行却出现“段错误”,你能确定出错的地方是这里吗,movw %bx,%ds:(0x0020)
语法没错呀

21,453

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧