2

I want to read the word at memory address 0000:FFFF, but when I debug my program:

org  0x7C00
mov  ax, 0x0000
mov  ds, ax
mov  ax, [0xFFFF]

executing the last instruction mov ax, [0xFFFF], will change CS:IP to F000:E9DF. So strange...

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Jack
  • 227
  • 3
  • 8
  • 2
    How are you single-stepping this, and in what debugger? And in what x86 simulator / emulator? Is it possible that garbage bytes in memory executed after that, and included a far `jmp`? Oh, or did a 2-byte access at `0xFFFF` cause a fault for exceeding the 64k segment limit, and `f000:e9df` came from the IDT? – Peter Cordes Oct 02 '18 at 13:06
  • Probably because the garbage in memory that follows your last instruction is interpreted as instructions and results in strange behavior. Use halt to stop the CPU execution. – m0skit0 Oct 02 '18 at 13:09
  • can you add `jmp $` to create infinite cycle and test after that? The CPU will otherwise wander into the memory executing everything it finds there... unless you are single-stepping it in debugger, then you should get the control right after the `mov ax,...`. – Ped7g Oct 02 '18 at 13:52
  • 2
    I use bochs as simulator. I try to add `jmp $` after `mov ax, [0xFFFF]`, but when `mov ax, [0xFFFF]` executed, CS:IP still change to F000:E9DF, and `jmp $` doesn't run... – Jack Oct 02 '18 at 14:11
  • 1
    While this is itself interesting, to solve your actual problem of reading a byte make sure you read just a single byte e.g. use `al` or `movzx ax`. – Jester Oct 02 '18 at 14:31
  • 5
    Reading a WORD at the end of a segment will cause a #GP (yes, even in real mode). – Margaret Bloom Oct 02 '18 at 14:33
  • @Jester Yeah! It works! But why I can't read word? – Jack Oct 02 '18 at 15:36
  • @MargaretBloom I'm a beginner, can you tell me what is GP? Thanks. – Jack Oct 02 '18 at 15:39
  • 1
    `#GP` is usual notation for General Protection Fault Exception. You can't read a word because address `0xFFFF` is the last byte in the segment, There is no other byte after it which would be needed for a word. – Jester Oct 02 '18 at 15:41
  • @Jester Ok, Thank you ^_^ – Jack Oct 02 '18 at 15:54

0 Answers0