Lil*_*lás 3 syntax x86 assembly real-mode gnu-assembler
我是x86程序集的新手,我正在尝试理解本文档中的代码:http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf第3页:
movw $0x1234, %ax
movw %ax, %ds
movw $0x5678, %bx
# The following instruction is the same as "movw $0x1337, (%bx)".
movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8.
# Segment Base: %ds << 4: 12340
# Offset: %bx: + 5678
# -------
# Linear Address: 179b8
Run Code Online (Sandbox Code Playgroud)
但我不理解这个命令:
movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8.
Run Code Online (Sandbox Code Playgroud)
为什么将%ds与(%bx)连接与((%ds << 4)|%bx)相同?
由于我处于实模式(16位),串联不应该是%ds << 8?而不是%ds << 4?
为什么括号只是%bx左右?而不是整个结构,如:movw $ 0x1337,(%ds:%bx)?
在实模式中,段寄存器用于提供20位地址.在这种情况下,数据段寄存器ds提供地址的"高"16位:(0x1234 << 4 = 0x12340),段中的偏移量由下式给出:0x5678,产生:0x179b8.
数据段寄存器是隐式的,因此不必使用:ds:(%bx).如果您正在使用其他段寄存器es,则需要明确.
我希望我理解你的问题.至于为什么它没有被写成(%ds:%bx),那真的只是一个你坚持的句法决定.