I'm in the middle of writing an assembler for uCIS...
# thinking-together
r
I'm in the middle of writing an assembler for uCISC in uCISC assembly (bootstrapping a language is fun). I'm happy with the progress I'm making, but a few things are standing out. 1) structuring the code is challenging since I don't yet have the higher level language paradigms (don't even have function syntax sugar at the level I'm at right now). 2) stack counting is tedious and I constantly get it wrong. I'm wondering if there are any resources, techniques or ideas on how to structure assembly code effectively. I feel like this may be a bit of a lost art.
Taking it a step further, I also realize that large computer systems need large complex structures to manage them. I'm wondering if, at some level, the complex structures in our higher level languages are only needed because of the large systems they were designed to enable.
k
How many registers do you have at this point? With 6 general-purpose registers (excluding stack management), I almost never had to use variables directly from the stack.
c
A left-field suggestion: Human Resource Machine winds up broadening your Assembly language skills. I found I learned a lot of things I'd forgotten; and it's fun to play 😉 https://tomorrowcorporation.com/humanresourcemachine Regarding your stack problem, I'm wondering if you could write some helper subroutines to manage the stack? A call to store the contents of the A register on the stack, for example, and one to retrieve it. You could store a stack count and inc/dec it. At the least you could error when you pop too far off the stack, etc.
❤️ 1
d
Back in the old days, assembly languages were intended for use by human programmers, and they were more sophisticated than those of today, which are really only intended for compiler code generation. Macro assemblers allowed you to write and use macros such as IF, SWITCH, FOR, WHILE, PROC, CALL. Expression-oriented assemblers allowed you to write more than one arithmetic opcode on the same line, using a syntax similar to arithmetic expressions. Try googling "macro assembler" or "high level assembler". Consider adding macros or high level features to the uCISC assembler.
1
k
I've been starting to feel the need for macros in Mu, just because of the constraint that addresses can't escape functions.
r
@Kartik Agaram I technically have 6 general purpose registers, but 3 are used for device access by convention. My guess is that I will end up being able to use 4 GP registers, one of which is the SP so an effective 3. One of the places I’m finding challenging is the function call boundaries. I recently ended up with a method that eats 1 position off the stack somewhere, but the function works perfectly if you don’t count the side effects. Then again, maybe I’m just doing it wrong 🤔.
@Chris Maughan @Doug Moen sounds like I just need to do the work for some macro basics. The lack of CALL macros in particular is tedious because there are a couple of boiler plate instructions needed to call a function and if I forget one, I just messed up my stack. Thanks for the tips. I’ll check out the game for fun and profit and google macro assembler.