Search code examples
assemblyx86nasm

Overcoming the BX-only-indexing restriction


I'm implementing a simple 0-terminated string printing function using BIOS interrupt int 10h.

The procedure is as follows:

  • Pop from stack into dx, this is the location at which our string starts
  • Set a counter in cx
  • Retrieve the byte at [dx + cx]. If 0, return, else mov to al
  • int 10h
  • Increment cx and jump back to point 3

The problem is nasm will only let me use bx as an index register. I believe this restriction's purpose isn't to make someone's life more difficult, so that would imply there's something wrong with my implementation. What is is, how can I overcome it?


Solution

  • In 16-bit mode you have to use BX. E.g. see here:

    For 16-bit addressing, the offset value can be in one of the three registers: BX, SI, or DI