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

SP points to last-1 instead of last push #10

Closed
Stokpan opened this issue Apr 13, 2023 · 3 comments
Closed

SP points to last-1 instead of last push #10

Stokpan opened this issue Apr 13, 2023 · 3 comments

Comments

@Stokpan
Copy link

Stokpan commented Apr 13, 2023

initial SP = 0000
run:

MVI A,F0H
INR A
PUSH PSW
HLT

SP = FFFD, it should be FFFE instead.

SP isn't pointing to the address containing the last PUSHed byte but rather the next available one. This is an error, according to Intel's specification (see 3-44, 3-45) it should be pointing to the address of the last one.

@FanisDeligiannis
Copy link
Owner

Nice catch! In order to adhere to that, I'm probably going to start the SP at address FFFE. It could still start at FFFF, but since every PUSH is pushing 16 bits, I'd like to keep those aligned nicely in the memory.

That way:

If SP=FFFE, the stack is empty
SP will always pointsto the last added data.
If SP > FFFE, you've popped an empty stack (which will, in the future, notify you and give you a warning).

Does that sound okay?

@Stokpan
Copy link
Author

Stokpan commented Apr 13, 2023

Sounds perfect, and FFFE is the starting address of some old, respected but outdated simulators.

@FanisDeligiannis
Copy link
Owner

Fixed as of edc7bc0.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants