boot_sect_memory.asm 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 starts loading 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. mov al, "3"
  21. int 0x10
  22. mov bx, the_secret
  23. add bx, 0x7c00
  24. mov al, [bx]
  25. int 0x10
  26. ; attempt 4
  27. ; We try a shortcut since we know that the X is stored at byte 0x2d in our binary
  28. mov al, "4"
  29. int 0x10
  30. mov al, [0x7c2d]
  31. int 0x10
  32. jmp $
  33. the_secret:
  34. ; ASCII code 0x58 is stored just before the zero-padding
  35. ; on this code that is at byte 0x2d (check it out using xdd)
  36. db "X"
  37. times 510-($-$$) db 0
  38. dw 0xaa55