The difference between the ptr byte and the word ptr

In a test article, I saw the following question:

Question

VarM DWORD ABBF01598h

Enter the contents of the registers al, bxand dlafter execution

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

Now I know the words ptr and the byte ptr by definition, but I can not understand them.

As for me

  • al = b
  • bx = 0
  • dl = F

Please help me figure this out. Thanks in advance.

+5
source share
2 answers

In those cases when you look, byte ptrand word ptrdo not do much. While harmless, the assembler already “knows” that alboth dlhave byte size and that it bxhas word size.

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

mov bx, some offset
mov [bx], 1

- , 1 , , , , . , :

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

() :

mov bx, some_offset
assume bx: ptr byte

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

: ( @NikolaiNFettisov). :

#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;
}

:

5040302

, dword ptr, 1 , 4. , -, , -, .

+11

. (), . , , 8- 16- ( 32- ..). # 1 , , ? , , , .

+1

All Articles