real_segmentation.S 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#real-mode-segmentation */
  2. #include "common.h"
  3. BEGIN
  4. CLEAR
  5. /* It is not possible to encode moving immediates
  6. * to segment registers: we must either:
  7. *
  8. * * pass through a general register ax
  9. * * pop from the stack
  10. */
  11. mov $1, %ax
  12. mov %ax, %ds
  13. mov %ds:msg, %al
  14. PUTC <%al>
  15. /* %ds is the default segment for GAS memory operations
  16. * if we don't write it explicitly.
  17. */
  18. mov msg, %al
  19. PUTC <%al>
  20. mov $1, %ax
  21. mov %ax, %es
  22. mov %es:msg, %al
  23. PUTC <%al>
  24. mov $1, %ax
  25. mov %ax, %fs
  26. mov %fs:msg, %al
  27. PUTC <%al>
  28. mov $1, %ax
  29. mov %ax, %gs
  30. mov %gs:msg, %al
  31. PUTC <%al>
  32. mov $1, %ax
  33. mov %ax, %ss
  34. mov %ss:msg, %al
  35. PUTC <%al>
  36. hlt
  37. msg:
  38. /* Push the correct A forward 16 bytes in memory
  39. * to compensate for the segments.
  40. */
  41. .fill 0x10
  42. .byte 'A'