0

I'm trying to learn how to write x86 machine code as hexadecimal (as part of putting text to the monitor on a qemu cold start.) My guess from reading a few sites was that the proper instruction to write 0x78073807 to 0xB8000 should be something along the lines of C7 00 80 0B 00 07 38 07 78 00 00 00 00 00 00 00. However, when putting this into a disassembler, the information it returns appears to indicate that this syntax is wrong. What am I missing here? Thank You!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Peach
  • 1
  • You can use `nasm -felf32 -l/dev/stdout foo.asm` to make correct examples to compare your attempts with. There are sometimes multiple correct ways to encode an instruction, but in this case there's only two, one of which has an unnecessary SIB byte so assemblers won't default to it. – Peter Cordes May 02 '22 at 04:44

1 Answers1

3

The code is missing the modr/m byte between the opcode C7 and the displacement and immediate.

mov dword [0x000B8000], 0x78073807

C7, 05, 00, 80, 0B, 00, 07, 38, 07, 78
Sep Roland
  • 33,889
  • 7
  • 43
  • 76