PNC
PNC

Reputation: 357

x86 assembly syntax check

We have an exam this coming week on x86 assembly and this segment of code confuses me a lot in the syntax check.

what does byte ptr, word ptr and etc means in x86 assembly?

for example NEG byte ptr [si] or NEG word ptr [si] I know that these two are valid syntax at x86 assembly but why NEG byte ptr si and NEG word ptr si are not valid?

Upvotes: 2

Views: 744

Answers (1)

Michael
Michael

Reputation: 58427

[si] is a memory operand, i.e. some data located in memory at the address specified by ds:si. If you just say NEG [si] the assembler won't be able to tell whether you want to negate a byte in memory, or a word (or a dword..).

Hence you use byte/word/dword ptr to disambiguate between different possible instruction encodings. For example, with NEG byte ptr [si] you tell the assembler that you want it to generate the machine code sequence that will negate the byte located in memory at ds:si.

NEG si on the other hand operates directly on the register si, not on memory. Since the size of si is known (it's 16 bits), there's no point in you specifying the size of the operand.

Upvotes: 5

Related Questions