Question

I'm reading assembly language for x86 processor's book

I'm trying to solve one of the chapter problems

Question is :

Insert the following variables in your program:

.data
Uarray WORD 1000h,2000h,3000h,4000h
Sarray SWORD -1,-2,-3,-4

Write instructions that use direct-offset addressing to move the four values in Uarray to the EAX, EBX, ECX, and EDX registers.

I write this code :

TITLE MASM Template                     (main.asm)

INCLUDE Irvine32.inc
.data
    arr1 WORD 1000h,2000h,3000h,4000h
    arr2 SWORD -1,-2,-3,-4

.code   
main PROC
    mov esi,OFFSET arr1
    mov eax,[esi]
    call DumpRegs
exit
main ENDP
END main

But the value of eax is 20001000 !

I cant understand why it isn't 00001000 ? why the first part become 2000?

And how can I fix it ?

Était-ce utile?

La solution

arr1 is an Array of WORDs i.e. 16-bit-values. mov eax,[esi] receives a 32-bit-value in this case two 16-bit-values. So you'll find in EAX the first and the second element of arr1. If you want to fill the whole EAX only with the first value use movzx eax, word ptr [esi] instead. This instruction fills the lower 16 bits of EAX with the element and nullifies the upper 16 bits.

Autres conseils

This happens because you declare arr1 as word, which is a 16-bit value, but you load a 32-bit dword from the address with mov eax,....

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top