2

How can I convert the following code into AT&T syntax?

mov es:[di], al

I'm trying to write a pixel to the screen with AT&T syntax in protected mode.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
user2997204
  • 1,344
  • 2
  • 12
  • 24
  • 1
    `mov %al,%es:(%di)` .That is a direct translation. But if you are in protected mode and are using a flat 32-bit memory model (typical) then just stick the 32-bit address into _EDI_ and do `mov %al, (%edi)` – Michael Petch Oct 17 '17 at 19:25
  • Should point out that `mov %al,%es:(%di)` is a direct translation it is only encodable if you are targeting as 16-bit code (won't assemble in 32-bit). If you know the value in _ES_ and the value in _DI_ you can compute the 32-bit address as ES*16+DI and use that in _EDI_ and use `mov %al, (%edi)` – Michael Petch Oct 17 '17 at 19:41
  • 1
    @MichaelPetch: NASM `-felf32` encodes `mov [es:di], al` without complaint. `objdump -d` says `26 67 88 05 mov %al,%es:(%di)`. I don't understand why binutils `gas` and `clang -c` won't encode it in 32-bit mode (even without `%es:`). Clang says "16-bit memory operand may not include only index register", but that's not true is it? Doesn't the address-size prefix make address decoding identical to 16-bit mode, where `[di]` is valid? And if it's not valid, why does NASM accept it in 32-bit code? – Peter Cordes Oct 18 '17 at 03:25
  • @PeterCordes I typed up the comment quickly, yes it is encodable in 32-bit code. As for CLANG and AS I think they are being anal about what represents base and index. I'd expect they would fail with something like `mov %al,%es:(,%di)` but I'd be surprised if this errors out `mov %al,%es:(%di)` – Michael Petch Oct 18 '17 at 03:40
  • @PeterCordes Are you trying to assemble that as 64-bit code? I could see those failing with .code64 but not .code32 or .code16 – Michael Petch Oct 18 '17 at 03:45
  • @MichaelPetch: Oh dammit, yes I think so. /facepalm. Yup, `-m32` did the trick. – Peter Cordes Oct 18 '17 at 03:46

0 Answers0