-
-
Notifications
You must be signed in to change notification settings - Fork 178
Description
This is gonna be the weirdest feature request, and I don't mind if you don't think it worth adding. But I've dabbled with some old Mainframe assemblers from back in the 70s, and one of them had an interesting feature they called "Literals".
Basically, you could put code in square brackets, and it would cause that code to be assembled in a block at the end of your code (you could also relocated this block to other places, and I think you could redefine it several times thru your code), and the square brackets would be replaced with the address it ended up getting assembled to.
So you could type things like:
ld hl, [.db "HELLO WORLD"]
call Print
and the string would get assembled to some place, and replaced in the hl with its address. You could also use it to call a short block of code that returns, things like that.
Like I said, while useful, this is not exactly a standard feature, and I don't mind if you don't think it worth adding.
Activity
aaaaaa123456789 commentedon Apr 5, 2020
The real issue is, where to put it? "Some place" isn't too descriptive. Perhaps at the end of the current section?
That being said, it seems like an interesting way to do jump tables:
LIJI32 commentedon Apr 5, 2020
It can be an explicitly marked constant pool, similar to ARM assemblers.
popeyeotaku commentedon Apr 5, 2020
The one I saw defaulted to the end of the assembly after your code, but there was a command to relocate it to wherever else you wanted
meithecatte commentedon Apr 5, 2020
Note that square brackets collide with memory accesses. In fact, this would mean that parsing is no longer context-free:
I'd suggest using curly braces instead.
Note that this kind of delimiters is used in quite a big family of languages already ;)
meithecatte commentedon Apr 5, 2020
Unresolved question: how would label scoping work here?
aaaaaa123456789 commentedon Apr 5, 2020
I assume locals before a global would be local to the braces and globals would work as always.
popeyeotaku commentedon Apr 5, 2020
I saw this feature in the rare MIDAS assembler for PDP-10, which you'd think would be hard to get working or find docs for, but actually an easy self installing emulation package and extensive documentation for Midas and its OS are here ITS on Github
ISSOtm commentedon Apr 5, 2020
Quick comment: parens, brackets and braces cannot work for this. Parens are used for expressions, brackets by memory accesses, and braces by symbol expansions (including outside of strings). So something else would be needed.
Other than that, I'm not really sure about how useful this is; my main concern with this is code mixed in the middle of data, which I'm afraid would hurt readability in cases more trivial than in the OP.
Implementation doesn't sound too complicated, but I'm seeing major pain points, such as specifying the location at which the code should be stored, or the fact that looks a lot like
LOAD
, which is already very fragile. From my point of view, this doesn't add anything significant (prove me wrong though) so I'm not sure if it's worth the additional complexity.ISSOtm commentedon Apr 5, 2020
After further discussion, I think this might be worth it though in fairly minor ways (compared to current solutions), so I won't close this, but this is low priority as far as I'm concerned. Anyone else willing to take a stab at it is welcome, however.
craben20 commentedon Apr 18, 2020
The proposition here is quite different from ARM assemblers. The literal pools there are typically used when numeric immediates are used that cannot be represented in 8-bits, (combined with some number of rotates as per the spec). It is also used for syntax like
LDR R0, =label
where label is an address label, not a storage directive as the OP desires. A literal pool would then be set up which contains the address oflabel
.tl;dr I don't think this is a good idea, not least for the combining code/data argument. Also, I can't imagine a use case where such a syntax would be appropriate.
aaaaaa123456789 commentedon Apr 18, 2020
In this case, double brackets would work perfectly. This might be complicated to parse, though, since the lexer would have to know to parse
[[
as a single token instead of reading it as two[
symbols. But this is a long-term feature anyway...Rangi42 commentedon Jan 23, 2021
If #244 were implemented, allowing two sections to be in the same bank even if they're floating, this could make use of it. The parser could allow
reloc_16bit
orreloc_16bit_no_str
to beinline_code
, which would parse as'[[' lines ']]'
. The[[
would push a new anonymous section in the same bank as the current one (also backing up the currentnListCountEmpty
andnPCOffset
values); the]]
would pop the section, restorenListCountEmpty
andnPCOffset
, and evaluate the whole inline code block to that section's address (with some newrpn_AddrSection
function likerpn_BankSection
).ISSOtm commentedon Jan 23, 2021
The problem of implementing #244 is that there's no way to adapt the bin packing algorithm to work with the additional constraints.
51 remaining items
Implement [[ inline fragments ]]
Implement [[ inline fragments ]]
[-][Feature Request] Literals, But It's Not What You're Thinking[/-][+][Feature Request] Literals (inline section fragments)[/+]Implement [[ inline fragments ]]
Implement [[ inline fragments ]]
Implement [[ inline fragments ]]
Implement [[ inline fragments ]]
[[ fragment literals ]]
#1614