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

Feature request: local labels associated with the *next* top-level label #214

Open
belkadan opened this issue Jan 6, 2025 · 0 comments
Open

Comments

@belkadan
Copy link

belkadan commented Jan 6, 2025

My own hobby ISA has a call instruction double as a return instruction. Therefore, if you put the function exit right before the entry label, the link register ends up being set to the function you just called, making it cheaper (in code size, by one byte) to call it again later. Unfortunately, actually branching to this return instruction from within the function body can't be done with a local label, because it's "outside" the function.

;; printCStringFromData2
;; Uses r0-r1
;; Precondition: r0 is the address of a C string in data2
;; Postcondition: r0 is the address just after the NUL terminator
printCStringFromData2_done:
	CABL ; Call ABsolute address in Link register
printCStringFromData2: ; this is the entry point
.loop:
	LD2U r0 ; load *r0++
	BEZI printCStringFromData2_done ; exit the loop on NUL
	PRNT ; print a single character
	JOFI .loop

I could of course make a workaround like having the label be at the CABL instruction and having the reference increment past it (probably with an expression), or having the branch to the function epilogue do some extra math, but what I'd really like is a way to say "this local label is associated with the next top-level label", whether that's a different spelling of the label (.,done, ~done, whatever) or a separate directive before the label (#section, whatever). That said, I totally get why nobody's done this yet…!

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

1 participant