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

what is the difference between these movw to AX and movb to AL load instructions, from an odd offset in .short array?

.global main

.data
arr: .short 1, 0xEA, 0x2, 0x3, 0b1010

.text
main:

      lea (arr), %rbx
      movb 3(%rbx),%al #1

      movw arr+3, %ax #2

when I try this code al gets the value 0x0 however ax gets the value 0x200
can you tell me why is that? what is the difference between #1 and #2 ?

>Solution :

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

Since x86 is a little-endian architecture, the data in arr looks like:

arr+0   +1   +2   +3   +4   +5   +6   +7   +8   +9
 0x01 0x00 0xEA 0x00 0x02 0x00 0x03 0x00 0x0A 0x00

#1 reads data to al. al is a one-byte register, so 0x00 at the +3 is loaded and the value becomes 0x0.

#2 reads data to ax. ax is a two-byte register, so 0x00 0x02 is loaded and the value becomes 0x200.

The difference is the size of the destination registers.

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