Skip to content

Instruction encoding inconsistency #3

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

Open
Shadlock0133 opened this issue Aug 7, 2020 · 3 comments
Open

Instruction encoding inconsistency #3

Shadlock0133 opened this issue Aug 7, 2020 · 3 comments
Assignees

Comments

@Shadlock0133
Copy link

I noticed that html docs specify loadsp/storesp as 0b011x_xxxx/0b010x_xxxx, but while disassembling hello_world's elf file with objdump (precompiled one from zylin/zpugcc), instruction 0x70 (0b0111_0000) decodes to loadsp 0, when I expected to see loadsp 64 (16 << 2). Clarification on what's happening would be very helpful.

@alvieboy
Copy link
Contributor

alvieboy commented Aug 8, 2020

Bit 4 is inverted for loadsp/storesp index. The documentation is wrong, I'll try to update it.
Meanwhile I have another instruction set reference you might take a look at:
http://alvie.com/zpuino/zpu_instructions.html#LOADSP

@alvieboy alvieboy self-assigned this Aug 8, 2020
@Shadlock0133
Copy link
Author

Reference you gave seem much nicer, I have just 2 remarks/nitpicks. In IM, when idim = 0, pushed value should be sign-extended. And in EMULATE, address of next instruction is pushed on stack, so IMO it should say Push( PC + 1 );

Do you happen to know, why loadsp/storesp flip the upper bit? Can't think of a reason how it would be useful.

Thanks for your help.

@alvieboy
Copy link
Contributor

alvieboy commented Aug 9, 2020

The reason is quite simple: it is due to the ADDSP encoding. The ADDSP instruction has bit 4 set to '1'. In order to generate a common offset from LOADSP/STORESP/ADDSP the simplest way (in hardware) is to negate this bit for all SP-relative operations, independenly of the opcode. This saves implementation resources.

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