The following code
section .data
Snippet db "KANGAROO"
section .text
global_start
_start:
mov ebx, Snippet
add byte [ebx], 32
is adding 32 to the number to which the memory address in BX refers to. However, what is the byte specifier after add? My book says that it means that we are only writing a single byte to the memory address in EBX. But I don't quite understand what that means (I am a beginner in assembler). What does it mean to write a byte to a memory address? What would it mean to write more than one byte?
byte [EBX], or in the case of microsoft assembler, byte ptr [EBX] tells the assembler that EBX is pointer to a byte sized variable. Defining the type of a pointer like this is only needed when using immediate values as operands. If using a register as an operand, then the assembler assumes the size is the same as the register, such as mov [ebx],al, or mov [ebx],ax, or mov[ebx],eax.
Not all
add
s are the same opcode. Nasm needs to know which to emit. If you saidadd word [ebx], 32
it would add a 16-bit 32 to[ebx]
and[ebx + 1]
. Similarly foradd dword [ebx], 32
. Since the upper bits of a 16- or 32-bit 32 would be zero, it wouldn't actually make any difference in this case (it would take more bytes to store the 32), but Nasm still needs to know which opcode to emit.