简体   繁体   中英

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 .

Whenever I try to run my code, it keeps saying there is an operand size conflict with mov test1, al and mov test2, ah .

My thinking is that each array is stored in esi and edi . I then store the first element into al or ah by getting their first memory address. 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. I am not sure why this is happening.

al and ah are 8-bit values (1 byte). 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.

If you want to store the values in the respective variables, you can use movzx (if unsigned) or movsx (if signed).


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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM