What does the following byte specifier for adding

2020-03-31 06:02发布

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?

标签: assembly nasm
2条回答
家丑人穷心不美
2楼-- · 2020-03-31 06:48

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.

查看更多
闹够了就滚
3楼-- · 2020-03-31 06:57

Not all adds are the same opcode. Nasm needs to know which to emit. If you said add word [ebx], 32 it would add a 16-bit 32 to [ebx] and [ebx + 1]. Similarly for add 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.

查看更多
登录 后发表回答