Search code examples
assemblygnu-assemblerattx86-16

How do I get a register to store an offset value in at&t syntax?


I am using this to write to the video memory (%es = 0xb800):

movw $0x074b,%es:(0x0)

However, what if I want the offset to be in %ax?

I tried %es:%ax, or %es:(%ax), but nothing worked, and I kept getting errors.

What am I doing wrong?


Solution

  • In 16 bit mode you are limited in usable address forms. You can't address using %ax. The valid forms are:

    • optionally one of bx or bp, plus
    • optionally one of si or di, plus
    • optionally a constant displacement

    As such, movw $0x074b, %es:(%di) would work, for example. See also Table 2-1. 16-Bit Addressing Forms with the ModR/M Byte in the official Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 2: Instruction Set Reference, A-Z

    PS: next time show what errors you got.