Explains that unless we specify a size operator (such as byte or dword) when adding an immediate value to a value stored at a memory address, NASM will return an error message.
section .data ; Section containing initialized data
memory_address: db "PIPPACHIP"
section .text ; Section containing code
global _start ; Linker needs this to find the entry point!
_start:
23 mov ebx, memory_address
24 add [ebx], 32
........................................................
24: error: operation size not specified.
Fair’s fair.
I’m curious as to why this is so however. As the two following segments of code will yield the same result.
add byte [ebx], 32
or
add dword [ebx], 32
So what difference does it make? (Other than not making much sense as to why you would use dword in this instance). Is it simply because “NASM says so”? Or is there some logic here that I am missing?
If the assembler can decipher the operand size from a register name, for example add [ebx], eax
would work, why not do the same for an immediate value, i.e. just go ahead and calculate the size of the immediate value upfront.
What is the requirement that means a size operator needs to be specified when adding an immediate value to a value at a memory address?
NASM version 2.11.08 Architecture x86
add byte [ebx],250
vsadd dword [ebx],250
... they should be the same according to your logic. But result will be different. – Arva