I'm writing a little machine code generator for assembly. I have a question regarding immediate to memory instructions:
Let's take these 3 scenarios:
"add [ebx+04], 0x1"
"add [ebx+04], 0x4040"
"add [ebx+04], 0x401000"
What I do is going by the immediate constant, I check what is the smallest number of bytes it can fit in then I assume whether its byte ptr, word ptr, dword ptr
First one can fit in 1 byte so I assume it to be:
"add byte ptr [ebx+04], 0x1"
Second can fit in 2 bytes so I assume it to be:
"add word ptr [ebx+04], 0x4040"
third fits in 4 bytes so I assume it to be:
"add dword ptr [ebx+04], 0x401000"
Is this correct?