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

Assembler improvement: Calculating labels #7

Open
tpwrules opened this issue Nov 5, 2019 · 1 comment
Open

Assembler improvement: Calculating labels #7

tpwrules opened this issue Nov 5, 2019 · 1 comment

Comments

@tpwrules
Copy link
Collaborator

tpwrules commented Nov 5, 2019

Currently, in the Python-based Boneless assembler, when specifying the name of a label in an instruction, e.g. MOVR(R3, "label"), the instruction operand is substituted by the PC-relative address of the label. This is the only way to use a label.

I propose a way to apply arbitrary calculations to labels before their values get substituted. Instead of specifying "label", the user could specify LabelCalc(lambda pc, lbl: label, "label") to the same effect.

By allowing an arbitrary lambda expression for the label, many other possibilities could be expressed. For example, LabelCalc(lambda pc, lbl: label-pc, "label") specifies the absolute location of "label". If there was an array with labels at the start and end, one could specify CMPI(R3, LabelCalc(lambda pc, s, e: e-s, "data_start", "data_end")) to test if R3 has reached the number of items in the array.

Based on my understanding of the assembler, this lambda expression would allow arbitrary calculations without changing its framework. However, there may be problems converging if the user specified a nonlinear calculation. In that case, there may need to be a check to fail assembly if there is no convergence after a reasonable number of iterations.

@whitequark
Copy link
Owner

By allowing an arbitrary lambda expression for the label

But that adds a disparity with the text assembler, which doesn't let you do that. And as you correctly note, makes convergence not always possible.

I think there should just be a way to compute using labels, like L("foo") - 1 or L("bar") - L("foo").

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