I suspect that passing parameters in registers probably makes the code shorter (especially important in a memory-limited micro machine) but a nightmare to port to another processor.
Yes shorter, in general. The BIOS is smaller because it doesn't have to pull stuff off the stack, and the caller is often shorter because it doesn't have to put stuff back on the stack. It can also help with a series of calls:
Code:
call kbscan ; wait for keypress and return scan code in A
call kb2ch ; convert scan code in A to ASCII returned in A
call prchar ; echo the character entered
cp A,' ' ; did the user type a control char?
jp c,.ctrl ; yes: handle it differently
; no: do whatever
No, not at all a nightmare to port for many things. Somehow it turned out that a lot of the old microprocessors have an
A register, so not only are the ports simple, but you can even use the exact same unit tests for all of them:
Code:
m.call(m.symtab.qdigit, R(a='F')) # parse digit
assert R(a=0x0F, m.regs)
Though this breaks down if you want to get super-anal and flag errors or something like that, not because of the register names, but because e.g the 8080/6800 has a carry/borrow flag but the 6502 has a carry/not-borrow flag. And the tricks you use for dealing with that in common unit tests handle different register names for different platforms as well. (See
src/generic/qdigit.py and the files that import it in
8bitdev.)
It probably depends upon whether you are talking about 'professional code' or 'amateur code' - for want of a better descriptive term for each.
I use "industrial code" for what I think you mean by the former: code that is robust and efficient, handling all the cases that are necessary to keep it from exploding, generally at the cost of clarity. I guess I would call code that makes for clear examples, while eliding all the extra work needed for industrial code, "naïve," both because it's naïve about what code like that really needs to do in the real world and because it's much easier for naïve users to read and understand the core functionality.
There's a third kind of code, "academic" code, which is the worst of them all because it's written by people who aren't even concerned about clarity but just, "can I convince a computer that my idea works, at least in an ideal world." Probably you won't even be able to get it to build unless you happen to be on the exact original system it was written on.