我正在使用平面汇编器以汇编语言处理 movsb 和 movsw 指令。现在,我注意到当执行 movsb 指令时,SI 和 DI 寄存器递增 1,而 movsw 指令则使 SI 和 DI 寄存器递增 2。我有点困惑为什么?谁能给我解释一下原因。我在下面添加了我的代码以用于带有注释的说明。请帮帮我。谢谢!
使用movsb指令(平面汇编器)
cld ;clear direction flag
lea si,[val] ;the memory address of source is loaded in the source register
lea di,[v];the memory address of the destination is loaded in the destination register
mov cx,5 ; the counter basically executes for the number of characters in the array
rep movsb ; repeats the instruction for 5 times
val:
db 'A'
db 'B'
db 'C'
db 'D'
db 'E'
v db 5 DUP(?)
Run Code Online (Sandbox Code Playgroud)
使用movsw指令(平面汇编器)
cld ;clear the direction flag
lea si,[a];load the address of a in source
;register
lea di,[b] ;load the address of b in destination
;register
mov cx,3
rep movsw ;copy each word from source to
;destination and increment the source register
;by 2 and destination register by 2
a:
dw '1'
dw '2'
dw '3'
b dw 3 DUP(?)
Run Code Online (Sandbox Code Playgroud)
小智 5
movsw,,,是用于将数据movsb从源位置复制到目标位置的指令。movsdmovsqDS:(ER)SIES:(ER)DI
它们很有用,因为IA32e 中 没有内存到内存的移动指令。
它们旨在循环使用(例如通过使用rep前缀),因此除了移动数据之外,它们还会递增(如果DF标志、方向标志为 0)或递减(如果DF标志为 1)指向源的指针和目标位置,即(ER)SI和(ER)DI寄存器。
从汇编程序员的角度来看,存储器是按字节寻址的,这意味着每个地址存储一个字节。
movsb移动一个字节,因此寄存器加/减 1。movsw移动一个 WORD(2 个字节),因此寄存器增加/减少 2。 movsd移动一个 DWORD(双字、2 个字、4 个字节),因此寄存器递增/递减 4。movsq移动一个 QWORD(四字,4 个字,8 个字节),因此寄存器增加/减少 8。| 归档时间: |
|
| 查看次数: |
3040 次 |
| 最近记录: |