-
Notifications
You must be signed in to change notification settings - Fork 11
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
16-bit ints #26
Comments
That's a good idea In the meantime, what do you say about making the interpreter have 16-bit mode? |
If we implement #30 i might try to make this. Since the framework for custom sized variables would exist then |
This pr may be what you suggested: |
This would probably be a long term thing.
A 16-bit is stored as 2 cells since this is an 8-bit compiler.
The 16-bit max value is
65535
.A 16-bit int is also called a short.
The number 512 would be stored as
2 0
.The number 12941 would be stored as
50 141
.The compiler would have to keep track of the type of the variable.
It would also need to keep track of the type of the variable that is going to be assigned.
Bools and chars should still be treated as ints
This would also mean we would have to implement 2 versions of every algorithm since it would have to support shorts.
Casting an 8-bit int to a 16-bit int could be hard but it could be done by making a copy of the 8-bit number and setting the lowest cell of the short to the copy.
A short is defined like this
Converting from an int to a short could be implemented as implicit casting but it would require more work from the compiler.
But it could also be implemented this way.
But there is a problem. What if we do:
The number literal 31 is an int, we would need a short.
The compiler would also need support for short temp variables for copying.
Since printing only supports 8-bit cells in an 8-bit environment, we should print the lowest cell, and reading a char would only fill the lowest cell if it is defined like this:
The library function
readint
would work with shorts but it would need some changes.Since this would also need to support arrays it would need to do some extra math to get the index.
1 dimensional array:
multidimensional array:
Implementation:
The pseudo code of shows some ways to implement some algorithms that would use shorts.
These algorithms only support shorts and not a mix of shorts and ints.
But there are some algorithms where I provided with a mix of shorts and ints
Basic Math:
Multiplication could be implemented in 2 ways:
Using the add code, or making a new algorithm.
Relational Operators:
To make a mixed version you could probably just replace
b.high
with 0The text was updated successfully, but these errors were encountered: