4 ms·
The Saturn assembly language (used on HP calculators, like the HP48) is not too difficult to read, compared to x86, Z80 or ARM. Here is a bit of code extracted
by stephc_int13 4y ago
The Saturn assembly language (used on HP calculators, like the HP48) is not too difficult to read, compared to x86, Z80 or ARM.
Here is a bit of code extracted from the Diamonds source code:
\* This is executed each time you die (with some lives left)
maSTART_OVER GOSUBL dsQUICK_DRAW draw the bricks quickly, not disolve
maSET_FLAGS ST=0 6 you can't knock out diamonds yet.
ST=0 7 you have no key
GOSUBL hbDRAW_KEY make sure no key is showing
LCHEX #00001 white brick
GOSUBL srSTO15_C erase mode
GOSUBL emDRAW_BRICK show erase brick
LC(5) BONUS_TIME a good time...
GOSUBL srSTO25_C bonus time
GOSUBL dlDRAW_LIVES draw lives left
GOSUBL srRCL6_C get level addr
C=C-CON A,5 now pointing to X,Y and DIR
D0=C in D0 (pointing to X)
C=0 A
C=DAT0 2 read X
GOSUBL srSTO0_C X
D0=D0+ 2 pointing to Y
C=DAT0 2 read Y
GOSUBL srSTO1_C Y
D0=D0+ 2 pointing to DIR
C=0 A
C=DAT0 1 read Direction
GOSUBL srSTO2_C store it
GOSUB grGET_READY display the GET READY window
- vidarh 4y agoI can't say I like that, but I'll note my first compiler on the Amiga started out as a wrapper around pure assembly, and supported similar arithmetic constructs where the asm generated was trivially predictable. E.g. similar to your example, you could write: D0.w = 42 .. to assign the immediate value 42 to the lower 16 bits of the D0 register (equivalent to MOVE.W #42, D0 in M68k assembly). Or: D0 = D0 + 2 (or D0 += 2) .. just as in your example ("ADD.L #2, D0"). You could also combine the asm with accessing variables etc. E.g.: D0 = x + 2 .. would be ("MOVE.L x, D0; ADD.L #2, D0" if x was a heap variable or "MOVE.L someoffset(SP), D); ADD.L #2, D0" if on the stack. But you could also just insert the assembly directly into the code... I wish I still had the source (it was initially written in assembly, and the gradually converted to itself); it was "interesting" writing a compiler where you could reliably intersperse higher level code with assembly "safely"
- Drakim 4y agoAh issue is that some (most?) architectures can't do math without messing with registers such as an accumulator, carry flag, negative flag, etc. While it looks convenient, I'm not sure I'd feel very confident about what happens with the CPU state using higher level syntax like that (especially if you want something more than a trivial addition)
- vidarh 4y agoThe thing is, it's not "higher level syntax" unless you make it higher level. It's the semantics that matters, and as stated in that case it was entirely deterministic which assembly instructions would get emitted. But of course that puts pretty hard limits on the compiler (e.g. no optimizations), and you end up doing low level programming just with a different syntax. That's to say, it looks convenient, and it was nice as a way of bootstrapping a simple compiler, but you're right to question whether the convenience is worth it.