I like reading these sorts of threads - mostly because it highlights my old saying of ask 10 programmers, get 11 answers...
It also demonstrates just how varied our world is with different people coming up with different ideas and styles - for different reasons....
My own coding style is often somewhat verbose and easy to read - and that's intentional. Until I'm really pressed for space I tend to not code for space efficiency (or even speed - until I really need it) so my preferred hex print code looks like:
Code:
;********************************************************************************
; oHex4: oHex8:
; Output the A register as 1 or 2 hex digits
; Preserves X, Y, A has last character printed.
;********************************************************************************
_oHex8:
pha ; Temp. save
lsr a ; A := A >> 4
lsr a
lsr a
lsr a
jsr _oHex4 ; Print top 4 bits as hex
pla ; Restore A and fall into ...
_oHex4:
and #$0F ; Isolate bottom 4 bits
phy
tay
lda hexTable,y
ply
jmp osWrch ; and return
hexTable: .byte "0123456789ABCDEF"
It's easy to read and follow, but yes, is a bit longer and has some extra guards in it to preserve Y - which in a more tighter system may be eliminated, but, for me, its easy to read now and re-read years later and easy to understand.
(and interesting choice of me using Y here - vs the use of X above - no difference in this instance, but just an interesting thing I note)
When I (re) started my 6502 love, I write my own 'wozmon' - it was much bigger than the Woz original, even bigger than the 2K one in the Apple II, but back then what were the constraints? RAM and ROM were very expensive, so Woz had to save every byte he could. I don't have that restriction, so is that making me lazy? Who knows.
I'd actually suggest I'm more lazy because I've never bothered with decimal mode on the 6502 - I've never, ever had a use for it in it's intended use-case, but it's very interesting to see little hacks like this.
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/