字节PTR和字PTR的区别 [英] Difference between byte ptr and word ptr

查看:307
本文介绍了字节PTR和字PTR的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个试纸以下问题,

I saw the following question on a test paper,

VarM DWORD ABBF01598h

给寄存器的内容 BX DL 执行后


  1. MOV人,字节PTR VarM + 1

  2. MOV BX,文字PTR VarM + 2

  3. MOV DL,字节PTR VarM + 3

  1. mov al, byte ptr VarM + 1
  2. mov bx, word ptr VarM + 2
  3. mov dl, byte ptr VarM + 3

现在我知道被定义字PTR和字节PTR,但我不能皮卡他们的概念。

Now I know word ptr and byte ptr by definitions but I am unable to pickup the concept of them.


  1. 人= B

  2. BX = 0

  3. DL = F

  1. al = b
  2. bx = 0
  3. dl = F

请帮我了解这些。提前致谢。

Please help me out in understanding these. Thanks in advance.

推荐答案

在情况下,你看,在字节PTR 字PTR 不大有作为。虽然无害,汇编已经知道 DL 的字节大小,而 BX 是字大小。

In the cases you're looking at, the byte ptr and word ptr don't accomplish much. While harmless, the assembler already "knows" that al and dl are byte-sized, and that bx is word-sized.

您需要像字节PTR 时,(例如)移动即时价值,间接地址:

You need something like byte ptr when (for example) you move an immediate value to an indirect address:

mov bx, some offset
mov [bx], 1

这通常不会被允许 - 汇编器没有办法知道你是否希望 1 写入一个字节,一个字,双字,可能是四字,还是什么。通过使用一个尺寸规格修复:

This won't normally be allowed -- the assembler has no way to know whether you want the 1 written into a byte, a word, a double-word, possibly a quad-word, or what. You fix it by using a size specification:

mov byte ptr [bx], 1  ; write 1 into a byte
mov word ptr [bx], 1  ; write 1 into a word
mov dword ptr [bx], 1 ; write 1 into a dword

您的可以的获得汇编接受的版本没有(直接)尺寸规格:

You can get the assembler to accept the version without a (direct) size specification:

mov bx, some_offset
assume bx: ptr byte

mov [bx], 1   ; Thanks to the `assume`, this means `byte ptr [bx]`

编辑:(主要是回复@NikolaiNFettisov)。试试这个简单的测试:

(mostly to reply to @NikolaiNFettisov). Try this quick test:

#include <iostream>

int test() { 
    char bytes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    _asm mov eax, dword ptr bytes + 1
}

int main() {
    std::cout << std::hex << test();
    return 0;
}

结果我得到的是:

The result I get is:

5040302

这表明即使我已经告诉了 DWORD PTR ,它只是加1的地址,而不是4.当然,有人写了不同的汇编程序的可以的采取不同的方式,如果他们选择。

Indicating that even though I've told it dword ptr, it's adding only 1 to the address, not 4. Of course, somebody writing a different assembler could do it differently, if they chose.

这篇关于字节PTR和字PTR的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆