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

Ideas for fixing variables #19

Open
aw opened this issue Nov 18, 2021 · 1 comment
Open

Ideas for fixing variables #19

aw opened this issue Nov 18, 2021 · 1 comment

Comments

@aw
Copy link
Contributor

aw commented Nov 18, 2021

As discussed previously, variables STATE, HERE, LATEST, TIB should be stored at memory addresses, not in registers.

Below are a few ideas which could help you:

  1. Store each variable at a memory location right below TIB_BASE_ADDR = 0x3000:
TIB = TIB_BASE_ADDR - 4
LATEST = TIB - 4
HERE = LATEST - 4
STATE = HERE - 4
  1. Since the values are in memory instead of registers, the body_fun needs a small change, example:
body_latest:
    li t0, LATEST # load memory address into temporary
    lw t0, 0(t0) # load address stored at LATEST into temporary
    sw t0, 0(DSP) # store address to top of data stack
    addi DSP, DSP, 4 # increment data stack by 32-bits
    j next
  1. Repeat for body_state, body_tib, etc... Well you know, there's quite a few other places this is needed, but if you had macros you could write one which performs those first two instructions (li and lw), so anywhere derzforth.asm makes use of LATEST, STATE, HERE, TIB could be replaced with t0 or something like that.. just a thought (I realize it's not going to be that simple).

I don't know if the above code is correct since I haven't tested it, but I think that's the idea.

@theandrew168
Copy link
Owner

After thinking more about where these "builtin" vars should go, I'm leaning toward putting at the base of the dictionary memory just after the interpreter. Since other user-defined vars will end up living in the dict memory, this will keep ALL vars within the same "block". Taking an extra 20 bytes from the interpreter / dict segment shouldn't be too big of deal.

Once the var locations are chosen, the code you wrote should do the trick. The body of each var's corresponding code word will look much the same. In the future, once I've got user-defined vars working, there might be a way to come back and have ALL vars (builtin and user-defined) share the same code path / helper funcs.

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