Search code examples
assemblyx86offsetx86-16

Assembly offset calculation rule


So... the rule of offset calculation states in my course book that:

offset = [bp] + [bx] + [di|si] + CONST  (any part is optional, but atleast one is required)

But reading on the internet i found the rule as :

offset = [bp|bx] + [di|si] + CONST 

Which one is it? And why?

(In my opinion the first should be also valid since bx could contain an arbitrary value like (1..F), but i tend to belive I am wrong and there must be a BX or BP)


Solution

  • The "internet rule" is correct. You can have 1 base register (bp or bx) and 1 index register (si or di). You can't have bp + bx or si + di at the same time. See Table 2-1. 16-Bit Addressing Forms with the ModR/M Byte in the Intel Instruction Set Reference

    Your course book is however correct that any part is optional but at least one is required, so you don't need a base or an index or an offset. These are all valid: [const], [bx], [si], [bx + si], [bp + di + const]. The full list is in the manual I linked above.