Search code examples
assemblysystemx86memory-segmentation

Writing to segment in x86


I would like to test how the hardware behaves in case I am trying to write into a segment ( for example a data segment other than DS maybe GS ) just for testing purpose ... Is there an assembly instruction that allow me to specify a segment wit.h an offset and directly write to it?


Solution

  • To write to a specific segment, you have to first load the segment number into a segment register and then do a load with an appropriate segment prefix. For example, to access 0x1234:0x5678, you can do something like this (in AT&T-syntax):

    push $0x1234
    pop %es
    mov %es:0x5678,%eax