boot_sect_memory_org.asm 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [org 0x7c00]
  2. mov ah, 0x0e
  3. ; attempt 1
  4. ; Will fail again regardless of 'org' because we are still addressing the pointer
  5. ; and not the data it points to
  6. mov al, "1"
  7. int 0x10
  8. mov al, the_secret
  9. int 0x10
  10. ; attempt 2
  11. ; Having solved the memory offset problem with 'org', this is now the correct answer
  12. mov al, "2"
  13. int 0x10
  14. mov al, [the_secret]
  15. int 0x10
  16. ; attempt 3
  17. ; As you expected, we are adding 0x7c00 twice, so this is not going to work
  18. mov al, "3"
  19. int 0x10
  20. mov bx, the_secret
  21. add bx, 0x7c00
  22. mov al, [bx]
  23. int 0x10
  24. ; attempt 4
  25. ; This still works because there are no memory references to pointers, so
  26. ; the 'org' mode never applies. Directly addressing memory by counting bytes
  27. ; is always going to work, but it's inconvenient
  28. mov al, "4"
  29. int 0x10
  30. mov al, [0x7c2d]
  31. int 0x10
  32. jmp $ ; infinite loop
  33. the_secret:
  34. ; ASCII code 0x58 ('X') is stored just before the zero-padding.
  35. ; On this code that is at byte 0x2d (check it out using 'xxd file.bin')
  36. db "X"
  37. ; zero padding and magic bios number
  38. times 510-($-$$) db 0
  39. dw 0xaa55