Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading