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 test1.
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 an 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.
>Solution :
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.