@alderwick I can't come on irc right now, but I've been toying with an idea and I'd like to have your opinion.

I was wondering if it would be a good idea to make it so the assembler merges sequences of byte literals into literal shorts. I've made a VERY POOR implementation of that in uxnasm to test, and in left there's more than a 100 bytes saved, and it makes the rom considerably faster.

I haven't been able to implement this in a way that doesn't make an absolute mess in the source yet-

· · Web · 1 · 0 · 3

@neauoire I'd love it if this optimised use of labels, so (silly example) “,&loop .Console/write” got merged into “LIT df18”. Does your patch do that already?

If it also optimised “.Console/write LIT &value 00” then that's more of a grey area. I intend that label should point to that 00 byte for writing a different value at some other time; but even then, conversion to “LIT2 18 &value 00” wouldn't break that use of code.

@neauoire I'm starting to realise how tricky this is to implement in uxnasm! I thought I was being clever with but now I realise that only affects pass 2, so all the labels after the first optimisation are wrong. 🙄

@alderwick yeah it has to be done on both pass, it makes quite a large mess.

Ideally it would handle all the literal byte runes `#`, `.` and `,`. I think I have just found a clever way to do one of the passes, but I'll keep you posted. If we can figure this one out, it would be a pretty good improvement.

@neauoire The way asma deals with the two passes is a different approach than uxnasm, it'll be good to let you know how.

The approach is to treat the two passes as similarly as possible, so instead of just counting bytes in pass 1 à la uxnasm, it “writes” them out to the ROM: the only differences are that in pass 1 the writes don't actually go to a file and if it doesn't know the value of a label, it makes up a junk value. With this approach, a hack to pushbyte() affects both passes equally…

@alderwick @neauoire Sorry to intrude but this double-pass thing in uxnasm/asma is just to account for label/sublabel references that are declared after being referenced? Or is it necessary for something else as well? I'm writing a compiler which performs only one pass but keeps a list of "future references" that are resolved in a second stage by... patching the resulting bytecode. Not elegant, but works for this single case

@tenshi @neauoire You're spot on, it's just for figuring out the values for every (sub)label 😊

@alderwick Talking about sublabels... where are File/length, File/write, et. al. defined? My compiler is not getting these right :/

@tenshi @alderwick they should be defined at the top! projects/library/asma.tal expects to be included from somewhere else.

projects/software/asma.tal has the File labels defined in line 5, and also it includes the other asma.tal in line 43:

@sejo @alderwick Oh! I grabbed asma from here:

Seems like I picked the wrong source file, which does not include these definitions haha thank you

@alderwick u just destroyed my brain with “.Console/write LIT &value 00” thanksss

@karolbelina Perhaps without the “.Console/write” in front, 😉 but “LIT @my-value 00” is one of my favourite ways of

1️⃣ saving space for a variable that's only read in one place in the code, but can be written in many places; and
2️⃣ summoning the elder gods of self-modifying code and confusion 🦑

@alderwick @karolbelina hmm, sorry to interrupt, but what is the difference between that and just @my-value $1?

@la_ninpre @karolbelina don't worry about interrupting! This is why we have these conversations in the Fediverse 😊

There's very little difference between "00" and "$1". In the middle of a Uxntal file it's all down to personal taste. At the end of the file, using only | and $ don't extend the resulting ROM, allowing labels to be placed "beyond" the end of file (which is all zeroes anyway).

Of course, if I needed 0000 then $2 is quicker to type, and $3 onwards have no equivalent.

@alderwick @karolbelina oh, thanks. tried it quickly and really something like |0200 LIT @my-value 00 at the end result in binary full of zeroes.

Sign in to participate in the conversation

Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them.