[英]I am not able to store an element of an array into a register using x86 assembly
The following is my code in assembly:以下是我在汇编中的代码:
mov esi, MemberLvl
mov edi, OfficerLst
mov al, [esi]
mov test1, al
mov ah, [edi]
mov test2, ah
In the C++ main program, I have declared a list of type long called MemberLvl and OfficerLst , and two long types - test1 and test2 .在 C++ 主程序中,我声明了一个名为MemberLvl和OfficerLst的长类型列表,以及两个长类型 - test1和test2 。
Whenever I try to run my code, it keeps saying there is an operand size conflict with mov test1, al
and mov test2, ah
.每当我尝试运行我的代码时,它总是说存在与
mov test1, al
和mov test2, ah
的操作数大小冲突。
My thinking is that each array is stored in esi
and edi
.我的想法是每个数组都存储在
esi
和edi
中。 I then store the first element into al
or ah
by getting their first memory address.然后,我通过获取第一个 memory 地址,将第一个元素存储到
al
或ah
中。 Because each long is 8 bytes and the al
or ah
register is 8 bytes, I'm thinking it will be able to store this into test1 and test2 (which are both declared a long, 8 bytes), but it isn't.因为每个 long 是 8 个字节,而
al
或ah
寄存器是 8 个字节,我认为它可以将它存储到test1和test2 (它们都声明为 long,8 个字节),但事实并非如此。 I am not sure why this is happening.我不确定为什么会这样。
al
and ah
are 8-bit values (1 byte). al
和ah
是8 位值(1 字节)。 test1
and test2
are "long" according to you, which is either 32 bit (4 bytes) or 64 bit (8 bytes), depending on your compiler / system.根据您的说法,
test1
和test2
是“长”的,它是 32 位(4 字节)或 64 位(8 字节),具体取决于您的编译器/系统。
If you want to store the values in the respective variables, you can use movzx
(if unsigned) or movsx
(if signed).如果要将值存储在各自的变量中,可以使用
movzx
(如果无符号)或movsx
(如果有符号)。
Also, note that if MemberLvl
is a long
, then moving it to esi
, then doing [esi]
is likely undefined behaviour, unless MemberLvl
happened to contain a valid pointer address.另外,请注意,如果
MemberLvl
是long
,然后将其移动到esi
,那么执行[esi]
可能是未定义的行为,除非MemberLvl
恰好包含有效的指针地址。 If MemberLvl
is a long *
, then it's probably fine, but then [esi]
is a 32 bit or 64 bit value, and thus you shouldn't use al
or ah
at all.如果
MemberLvl
是long *
,那么它可能没问题,但是[esi]
是 32 位或 64 位值,因此您根本不应该使用al
或ah
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.