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

Could you please add CS, IP register? #18

Open
wathenjiang opened this issue Nov 13, 2021 · 4 comments
Open

Could you please add CS, IP register? #18

wathenjiang opened this issue Nov 13, 2021 · 4 comments

Comments

@wathenjiang
Copy link

wathenjiang commented Nov 13, 2021

As we know, 8086CPU has 14 registers, but 8086-emulator-web lacks both of CS and IP.

I want to verify this theory that jmp ax:bx semantically equivalent to execute mov cs,ax & mov ip,bx.

Could you please add CS & IP? Or just tell me why this emulator does not include CS and IP.

@wathenjiang
Copy link
Author

And it seems do not support all feature of jmp command,
image
ref: wiki-JMP (x86 instruction)

@YJDoc2
Copy link
Owner

YJDoc2 commented Nov 13, 2021

Hey,
Thanks for using the emulator!

So the answer for both of your questions is same : it is because the emulator does not translate the instructions to an actual bytecode.

The way emulator works now, is in first pass it converts the code to a simple intermediate representation, which is text based. Then instead of converting that to bytecode, which would be stored in memory, the actual running of program is done directly from this text-based IR, where each instruction is parsed and evaluated each time it is to be run.

Ideally, the IR should be converted to a bytecode which then should be stored in the memory ; but when making this, we could not find a definitive definition of Hex codes for 8086 assembly. The few sources which we found seemed to disagree with each other and did not cover all the instructions, so we kept the IR text-based. (We could have defined out own bytecode, but we didn't).

Thus we cannot actually store the instructions in the memory like the data is stored. Hence there is no meaning of CS and IP, as we cannot treat any place in memory as the "code" segment, and the IP is maintained internally by the emulator, and it should be modified.

For the same reason, the jmp instruction only supports jumping using labels, as any memory address given explicitly or in register cannot be an instruction address.

In case you have any idea about 8086 asm hex codes, we can try implementing that, or if you have any idea of making a consistent bytecode for all ~100 instructions, please feel free to mention!

@wathenjiang
Copy link
Author

Thx for your replying.

Your project is awsome. When the code work with memory, I found it does not work well. Such as mov [0],cx, cs:ip.

The implementation details you gave us tells me the reson why such type of code does not work well.

@YJDoc2
Copy link
Owner

YJDoc2 commented Nov 13, 2021

Your project is awsome

Thank you!

When the code work with memory, I found it does not work well. Such as mov [0],cx, cs:ip.

For the reasons explained above, cs and ip will not work in code. For the mov [0], cx example, it will give error because you need to explicitly tell that the memory you are giving the address of should be treated as byte or word. That way mistakenly using cx which is a 16 bit register when you wanted to move 8-bit value is prevented. The correct syntax for this in the emulator is mov word [0], cx.

You can check out the instructions page on the website : https://yjdoc2.github.io/8086-emulator-web/help for details of the instruction syntax. This lists all the instructions, and the operands supported by them. For example , for move :
syntax of mov instruction

This specifies, that for mov instruction using memory as one of the operand, you need to add "byte" or "word" in front of it.

Hope this will be helpful.

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