8086-Emulator icon indicating copy to clipboard operation
8086-Emulator copied to clipboard

Memory offset wraparound is not correct

Open neldredge opened this issue 2 years ago • 3 comments

With ds = 0, mov word [0xffff], 0xbeef should write bytes 0x0ffff and 0x00000: the offset should wrap around but not propagate its carry. Instead it writes 0x0ffff and 0x10000.

To fix this, I think one needs to change inc_addr to take a segment and offset, instead of just a linear address.

neldredge avatar Mar 09 '23 03:03 neldredge

Hey, it seems correct and incorrect at the same time for me :sweat_smile:

In some sense, it feels more correct to wrap the offset and not the final address, but in some other it feels correct to do the other way. I tried checking the manual, and can't find the description of addressing modes for this case at the moment. Give me some time to think on this.

Also, if you know a reliable place where the addressing is described properly, can you share that?

YJDoc2 avatar Mar 09 '23 05:03 YJDoc2

The 8086 User's Manual does say on page 2-12:

Note that this addition process provides for modulo 64k addressing (addresses wrap around from the end of a segment to the beginning of the same segment).

That maybe doesn't directly address wraparound within one instruction, but I'm also looking at the 80386 Programmer's Reference Manual. On page 14-6, discussing differences between 8086 and 80386, it says:

On the 8086, an attempt to access a memory operand that crosses offset 65,535 (e.g., MOV a word to offset 65,535) or offset 0 (e.g., PUSH a word when SP = 1) causes the offset to wrap around modulo 65,536.

neldredge avatar Mar 09 '23 05:03 neldredge

In that case it should be indeed implemented that way. Can you link both of the manuals in your comment (just so we have a ref)? Thanks!

YJDoc2 avatar Mar 09 '23 05:03 YJDoc2