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

Different length for instructions and data? #39

Closed
p-rivero opened this issue May 9, 2020 · 5 comments
Closed

Different length for instructions and data? #39

p-rivero opened this issue May 9, 2020 · 5 comments

Comments

@p-rivero
Copy link

p-rivero commented May 9, 2020

Hi, I'm working on an 8 bit computer with 16 bit (2 byte) instructions. Those 2 bytes are stored at the same address, so the issue I'm facing is that the pc from the assembler gets increased by 2, when it should only be increased by 1. This causes jumps to a label to not work.

The solution would be to use #bits 16 but that messes up the data memory. Is there any way to use #bits 16 on the program bank and #bits 8 on the data bank?

I currently have a workaround (accept an address as u9 instead of u8 and ignore the last bit), but I'd like to know if there is a native solution.

Thank you for this great program.

@hlorenzi
Copy link
Owner

hlorenzi commented May 9, 2020

Hi! I'm glad you're finding it useful!

Could you please post an example program, showing the problem and your workaround? I'd like to make sure I'm getting the problem right. I'm not sure how your program bank integrates with the data bank -- there are two address spaces?

@p-rivero
Copy link
Author

In order to make the most out of 8 bit addresses, there are 4 address spaces: instruction low, instruction high, data and stack (the stack isn't important since you don't program it directly).
This means that even though addresses are technically 2 byte long, the PC ony gets increased by one when jumping to the next one.
example
Untitled-1
Note that the output position in the file (outp column) is correct. The only problem is the wrong address, that causes jumps to go to twice the correct position,

Using #bits 16 means that the data bank stops working completely, so I used #bits 8 and came up with this solution:
Instead of defining a jump like this: J {Addr8: u8} -> { 0xA0 @ Addr8[7:0] }
I define it like this: J {Addr8: u9} -> { 0xA0 @ Addr8[8:1] }, so the address gets divided by 2.
Also in bankdef for the program I have to set the #size as twice the actual size.
The ony drawback is that when you type the address instead of using a label it doesn't work (because the number you type will get divided by 2), but you shouldn't be doing that anyways.

Thank you for your time and hard work 👍

@p-rivero
Copy link
Author

p-rivero commented Oct 6, 2020

The issue seems to have been solved in v0.11 with the ability to set #bits for each bank. However, it looks like it doesn't work unless I type the directive every time I want to change banks:

#bank data
#bits 8
...

#bank program
#bits 16
...

Is this a bug or intended behaviour? I think the #bank directive should set the #bits automatically if you already specified it in the bankdef

@hlorenzi
Copy link
Owner

hlorenzi commented Oct 6, 2020

Oops, sorry! I've fixed this in v0.11.1. Could you let me know if it's now working for you?

@p-rivero
Copy link
Author

p-rivero commented Oct 7, 2020

Yes, now it's working perfectly. 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