Reputation: 51
In ecx
I have some string, like "abc"
.
mov ah, BYTE PTR [ecx+0]
mov al, BYTE PTR [ecx+1]
What does it exactly do? It's like in ah
I have "a"
and in al
I have "b"
?
Upvotes: 1
Views: 34799
Reputation: 3233
There are times when we need to assist assembler in translating references to data in memory.
byte ptr
-> it simply means that you want to fetch a byte from the address.
if it said word ptr
or dword ptr
, you would get a word or dword from the address in source index.
When you need something like byte ptr
example you move an immediate value to an indirect address:
mov ebx, OFFSET some_symbol ; or a pointer from another register
mov [ebx], 10
This won't normally be allowed -- the assembler doesn't know whether you want the 10 as a byte
, a word
, a double-word, or (in 64-bit code) a quad-word. You need to make it explicit with a size specification:
mov byte ptr [ebx], 10 ; write 10 into a byte
mov word ptr [ebx], 10 ; write 10 into a word
mov dword ptr [ebx], 10 ; write 10 into a dword
Upvotes: 4
Reputation: 93014
byte ptr
indicates that the memory operand refers to a byte in memory as opposed to a word or dword. Usually, this can be omitted as the assembler can infer the operand size from registers used but there are some instructions like mov [eax],0
where the size cannot be inferred, so a byte ptr
, word ptr
or dword ptr
prefix is needed.
Upvotes: 5