Article View: comp.lang.forth
Article #235Re: writing an AVR disassembler
From: Ivan Shmakov
Date: Tue, 17 Nov 2026 19:35
Date: Tue, 17 Nov 2026 19:35
50 lines
3425 bytes
3425 bytes
>>>>> On 2026-11-17, dxf wrote: >>>>> On 16/11/2026 11:57 am, dxf wrote: >>>>> On 16/11/2026 9:55 am, Ivan Shmakov wrote: >>> I /think/ that UNNIBBLE in particular can be made simpler, but it's not >>> obvious to me how. (Or do I just use some built-in word here instead?) >> My 'built-in' (kernel) word is >DIGIT and was designed to be 'general >> purpose'. It's coded in assembler but here's a high-level version. >> It's case-sensitive to handle situations where lowercase would amount >> to an error. It returns 'char' in the event of error should one want >> to print it. >> : >DIGIT ( char base -- u true | char false ) >> over [char] 0 - dup #10 #17 within 0= if dup #16 u> >> if 7 - then dup rot u< if nip true end dup then >> 2drop false ; > According to pForth (github) it has DIGIT with the same stack effect > as mine. It differs in that it is case-insensitive i.e. 'a' is treated > as 'A'. Based on that, then this should work: > : UNNIBBLE ( c - n ) > ( Convert a hex digit character into a number ) > 16 DIGIT 0= ABORT" character not in the 0-9a-fA-F range" ; ACK, thanks, it does. I'd say it ends up being more complex this way: DIGIT is implemented in pForth itself (see fth/numberio.fth), and is fairly involved at that, but my code is a prototype anyway, so it makes every sense to use what suitable built-in words that might be available. Like I've said, I intend for the code to eventually run on the MCU itself, and I expect an AVR Forth to be closer to, say, Pygmy Forth, than pForth. About the only reason I'm not writing this prototype in Pygmy is that I haven't figured out a good way to send bits of code from Vi(m) to that particular implementation (even with "CTTY AUX" and ">DOS". "INCLUDE CON", perhaps?) Regardless, Pygmy has -DIGIT , which is similar, but with it using BASE , it's far less suitable: p> : -DIGIT ( c - n) $30 - DUP 9 > IF 7 - DUP $A < OR THEN p> DUP BASE @ U< NOT ABORT" ?" ; Another thing to note is that "7" both here and in >DIGIT above is ASCII-specific. I have no plans for supporting, say, EBCDIC, but something like an explicit [ CHAR A CHAR 9 - 1- ] might be helpful should anyone desire to port the code to such an environment.
Technical Details
Message-ID:
<V6glmhG8TI8QaF1O@violet.siamics.net>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<UOSz15Vn9V7SG_X-@violet.siamics.net> <6afa54e3$1@news.ausics.net> <6afc6a01$1@news.ausics.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Ivan Shmakov <ivan@siamics.netREMOVE.invalid> Newsgroups: comp.lang.forth Subject: Re: writing an AVR disassembler Date: Tue, 17 Nov 2026 19:35:20 +0000 Organization: Dbus-free station. Lines: 50 Message-ID: <V6glmhG8TI8QaF1O@violet.siamics.net> References: <UOSz15Vn9V7SG_X-@violet.siamics.net> <6afa54e3$1@news.ausics.net> <6afc6a01$1@news.ausics.net> Injection-Date: Tue, 17 Nov 2026 19:35:48 +0000 (UTC) Injection-Info: dont-email.me; logging-data="778084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/s5gwpgfMpyHMSHhGNosGa"; posting-host="c09cd95e4b200ec717b95ae4665477ec" Cancel-Lock: sha1:8HUDBHuODqfaPjGlcboS3rokOu0= sha256:m/J3u3ff4XJyQmbYxRxmmgbiJ9/pWbO/AfLJ001s4wQ= sha1:cLh4lMyPHzuPEFvm8RfhO7c2AFc= sha256:jcBkfJEzURuJa/otP0G5YQSoMsESX1rhbGnVx2p11BM= License: CC0-1.0 (original contributions only)