简体   繁体   English

使用偏移访问数据段

[英]access data segment using offset

I'm reading assembly language for x86 processor 's book 我正在阅读x86处理器书籍的汇编语言

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. 编写使用直接偏移寻址的指令,将Uarray中的四个值移动到EAX,EBX,ECX和EDX寄存器。

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 ! 但是eax的价值是20001000!

I cant understand why it isn't 00001000 ? 我不明白为什么它不是00001000? why the first part become 2000? 为什么第一部分成为2000年?

And how can I fix it ? 我该如何解决?

发生这种情况是因为您将arr1声明为word ,这是一个16位值,但是您使用mov eax,...从地址加载32位双字。

arr1 is an Array of WORDs ie 16-bit-values. arr1是一个WORD数组,即16位值。 mov eax,[esi] receives a 32-bit-value in this case two 16-bit-values. mov eax,[esi]在这种情况下接收32位值两个 16位值。 So you'll find in EAX the first and the second element of arr1 . 所以你会在EAX中找到arr1的第一个和第二个元素。 If you want to fill the whole EAX only with the first value use movzx eax, word ptr [esi] instead. 如果你想用第一个值填充整个EAX,请使用movzx eax, word ptr [esi]而不是movzx eax, word ptr [esi] This instruction fills the lower 16 bits of EAX with the element and nullifies the upper 16 bits. 该指令用该元素填充EAX的低16位,并使高16位无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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