boot_sect_memory.asm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. mov ah, 0x0e
  2. ; attempt 1
  3. ; Fails because it tries to print the memory address (i.e. pointer)
  4. ; not its actual contents
  5. mov al, "1"
  6. int 0x10
  7. mov al, the_secret
  8. int 0x10
  9. ; attempt 2
  10. ; It tries to print the memory address of 'the_secret' which is the correct approach.
  11. ; However, BIOS places our bootsector binary at address 0x7c00
  12. ; so we need to add that padding beforehand. We'll do that in attempt 3
  13. mov al, "2"
  14. int 0x10
  15. mov al, [the_secret]
  16. int 0x10
  17. ; attempt 3
  18. ; Add the BIOS starting offset 0x7c00 to the memory address of the X
  19. ; and then dereference the contents of that pointer.
  20. ; We need the help of a different register 'bx' because 'mov al, [ax]' is illegal.
  21. ; A register can't be used as source and destination for the same command.
  22. mov al, "3"
  23. int 0x10
  24. mov bx, the_secret
  25. add bx, 0x7c00
  26. mov al, [bx]
  27. int 0x10
  28. ; attempt 4
  29. ; We try a shortcut since we know that the X is stored at byte 0x2d in our binary
  30. ; That's smart but ineffective, we don't want to be recounting label offsets
  31. ; every time we change the code
  32. mov al, "4"
  33. int 0x10
  34. mov al, [0x7c2d]
  35. int 0x10
  36. jmp $ ; infinite loop
  37. the_secret:
  38. ; ASCII code 0x58 ('X') is stored just before the zero-padding.
  39. ; On this code that is at byte 0x2d (check it out using 'xxd file.bin')
  40. db "X"
  41. ; zero padding and magic bios number
  42. times 510-($-$$) db 0
  43. dw 0xaa55