Difference between MOV and MOV ptr

Asked

Viewed 185 times

4

Maybe it’s not the ideal place to ask this, but I’m having a test and I don’t understand the difference between MOV and MOV ptr. for example, if we have in c language "unsigned char x,y", in Assembly if we want "X=2" we use MOV x,2

but if we have "unsigned char tabbyte[4]" and we want "tabbyte[0]=15" we already use
MOV byte ptr tabbyte [0],15.

Can anyone explain the difference to me, and when we should simply use MOV and when we should use MOV ptr? Thank you

1 answer

2


It seems you’ve seen this here.

The explanation is what is there on the link.

In an instruction of the kind

 mov [ESI], al ; Store a byte-size value

the Assembler (masm, tasm, etc.) knows which machine instruction to use, because the origin is the AL register that has 8 bits (1 byte).

In an instruction of the kind

mov [ESI], 5   ; Error: operand must have the size specified

the Assembler does not know which machine instruction to use, because "5" can be a byte with value 5, or a word with value 5, etc.

Then you need to give the Assembler more information so it can generate the right machine instruction:

; move o valor 0x05 (8 bits) para o byte cujo endereço está em ESI
mov  BYTE PTR [ESI], 5

; move o valor 0x0005 (16 bits) para a word cujo endereço está em ESI
mov  WORD PTR [ESI], 5

; move o valor 0x00000005 (32 bits) para a double-word cujo endereço está em ESI
mov  DWORD PTR [ESI], 5

Note that although the Assembly instruction is the same in these 3 cases (MOV) actually the machine code is different, so the Assembler program (masm, tasm, etc) needs this additional information: byte ptr, word ptr, dword ptr.

PS. in my previous answer on this subject I did not worry much about it, by guarantee I used byte ptr, word ptr, maybe even in places where it was not strictly necessary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.