Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory offset wraparound is not correct #12

Open
neldredge opened this issue Mar 9, 2023 · 3 comments
Open

Memory offset wraparound is not correct #12

neldredge opened this issue Mar 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@neldredge
Copy link

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.

@YJDoc2
Copy link
Owner

YJDoc2 commented Mar 9, 2023

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

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?

@neldredge
Copy link
Author

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.

@YJDoc2
Copy link
Owner

YJDoc2 commented Mar 9, 2023

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 YJDoc2 added the bug Something isn't working label Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants