为什么存储在存储器中的数据被颠倒了? [英] Why is data stored in memory reversed?
问题描述
这是我拥有的源代码:
section .data
msg: db "pppaaa"
len: equ $
section .text
global main
main:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
当我调试此代码时,我会看到:
And when I debug this code I will see:
(gdb) info register ecx
ecx 0x804a010 134520848
(gdb) x 0x804a010
0x804a010 <msg>: 0x61707070
(gdb) x 0x804a014
0x804a014: 0x00006161
显然,"70"代表字符"p","61"代表字符"a".
"70" here represents the character 'p' and "61" the character 'a' obviously.
我感到困惑的是,为什么位置0x804a010中的数据为0x61707070(appp),并在0x804a014处向前移动4个字节,数据为--aa?
What I am confused about is, why is the data in location 0x804a010 is 0x61707070 (appp) and moving 4 bytes forward at 0x804a014 the data is --aa ?
我希望第一个位置看到(pppa),第二个位置看到(aa--).为什么会这样?
I would expect to see (pppa) for the first location and (aa--) for the second location. Why is this the case?
推荐答案
GDB不知道您有一堆字符.您只是要求它查看一个内存位置,并显示那里的内容,默认为4字节整数.它假定该整数首先存储了最低有效字节,因为这是在Intel上完成的,因此您的字节反转了.
GDB doesn't know that you have a bunch of chars. You are just asking it to look at a memory location and it is displaying what is there, defaulting to a 4-byte integer. It assumes the integer is stored least significant byte first, because that is how it is done on Intel, so you get your bytes reversed.
要解决此问题,请在您的 x
命令中使用格式说明符,如下所示:
To fix this, use a format specifier with your x
command, like this:
x/10c 0x804a010
(将从0x804a010开始打印10个字符).
(will print 10 chars beginning at 0x804a010).
help x
将提供更多信息.
这篇关于为什么存储在存储器中的数据被颠倒了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!