内存复制操作如何依赖字节顺序?

How does memory copy operations depend on Endianess?

我刚做了一个汇编语言编程,结果发现我的代码不起作用。我浏览了代码,发现了我对 Endianess 理解的问题。

我的系统是Little Endian,我的代码如下:

lbDest:
            .byte 0x0000
            .byte 0x0000
            .word 0x0000
            .word 0x0000

上面是我应该将值复制到的目标,下面是要复制的来源,

lbSrc:

        .byte 0x00
        .byte 0x00
        .long 0x00000001
        .long 0x00

我将值从 Source 复制到 Destination 的代码如下:

       movw $lbSrc, %si
       movw $lbDest, %di
lbTempLoop:

        addw [=12=]x02, %si
        addw [=12=]x02, %di
        movw (%si), %ax
        movw %ax, (%di)
        loop lbTempLoop

概念:

这个概念就像是,从 lbSrc 复制 .long 值并将其放在两个单词 .word 中,然后在获取单词时再次获取相同的值那是在 .long.

注意:上面的代码是运行在16位环境下的,因此movl这样的指令不合适。

OS: Ubuntu

汇编程序:GNU AS

字节序:小字节序

谢谢

循环的两次迭代将产生以下结果:

lbDest:
    .byte 0x0000
    .byte 0x0000
    .word 0x0000     This will recieve a value of 1 (low word of the long)
    .word 0x0000     This will recieve a value of 0 (high word of the long)

进一步的迭代将开始覆盖未在此处定义的目标中的内存!

    movw [=11=]x02, %cx
    movw $lbSrc, %si
    movw $lbDest, %di
lbTempLoop:
    addw [=11=]x02, %si
    addw [=11=]x02, %di
    movw (%si), %ax
    movw %ax, (%di)
    loop lbTempLoop