Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hex Display Words

722 views
Skip to first unread message

Rick C

unread,
Jan 14, 2021, 1:38:36 PM1/14/21
to
I am working on some code to help me design a math circuit in an FPGA and I'm not finding much in the way of display words for double numbers. There is H. in Win32Forth to display a number as hex which I assume is common, but nothing for double numbers. Would DH. be appropriate nomenclature? Or HD. ?

This word actually prints an underscore every four digits so not strictly like D. or H. Is there a naming convention for that sort of thing, like separators every three digits in decimal numeric displays?

: dh. ( d - )
base @ -rot #16 base !
<# 0 begin -rot # 2dup D0= 0= while
rot 1+ dup 4 mod 0= if '_' hold then repeat
drop s" 0x" holds #>
type base ! ;

In case anyone is interested. I'd also welcome comments on the code.

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

NN

unread,
Jan 14, 2021, 4:57:01 PM1/14/21
to
If H. doesnt print leading zeros, then numbers wont line up, assuming you want them to.
However you can do what you have done above or more simply just define

\ remember you are passing doubles.
: (h.) ( d -- ) <# # # # # '_' hold # # # # ':' hold # # # # '_' hold # # # # #> type ;
: dh. ( d -- ) hex (h.) decimal ;

eg
4294967295. dh. 0000_0000_FFFF_FFFF
1 4294967295 dh. FFFF_FFFF:0000_0001

you get the idea.

P Falth

unread,
Jan 14, 2021, 5:03:39 PM1/14/21
to
On Thursday, 14 January 2021 at 19:38:36 UTC+1, gnuarm.del...@gmail.com wrote:
> I am working on some code to help me design a math circuit in an FPGA and I'm not finding much in the way of display words for double numbers. There is H. in Win32Forth to display a number as hex which I assume is common, but nothing for double numbers. Would DH. be appropriate nomenclature? Or HD. ?
>
> This word actually prints an underscore every four digits so not strictly like D. or H. Is there a naming convention for that sort of thing, like separators every three digits in decimal numeric displays?
>
> : dh. ( d - )
> base @ -rot #16 base !
> <# 0 begin -rot # 2dup D0= 0= while
> rot 1+ dup 4 mod 0= if '_' hold then repeat
>
> type base ! ;
>
> In case anyone is interested. I'd also welcome comments on the code.
>

I would call it D_H. just to remember that it uses an unusual delimiter.
I would also factor it like this

: 4# ( d -- d f ) # # # # 2dup or if '_' hold 0 else s" 0x" holds -1 then ;
: D_H. ( d -- ) base @ -rot #16 base ! <# begin 4# until #> type base ! ;

In difference from yours this version always prints groups of 4 digits.
zero will become 0x0000. I like it that way.

BR
Peter Fälth

Rick C

unread,
Jan 14, 2021, 5:08:17 PM1/14/21
to
Actually, no, I don't get the idea. I'm not clear at all what you are trying to show. I'm not trying to line up numbers. I also don't understand why your first test case prints an underscore as the middle separator and the second test case prints the : as it appears the code would should produce. Can you explain what happened?

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 14, 2021, 5:10:33 PM1/14/21
to
Fair enough. The reality is I will most likely have a version that prints a specified number of digits like D.R. Good idea about the D_H. name. Thanks.

--

Rick C.

-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209

NN

unread,
Jan 14, 2021, 5:37:32 PM1/14/21
to
I copied and pasted as I tested.
Well done for spotting that the middle separator changed.
I didnt like the _ , so I changed it so I can see cell : cell .

I thought you were trying to print a double-celled value as a hex number.
Clearly I have answered the wrong question.




Rick C

unread,
Jan 14, 2021, 7:45:44 PM1/14/21
to
Fair enough, but I don't understand how you got this output
4294967295. dh. 0000_0000_FFFF_FFFF
using the code you posted. ???

This is what I get.
4294967295. dh. 0000_0000:FFFF_FFFF

Was the 0000_0000_FFFF_FFFF output from another version of your program?

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Gerry Jackson

unread,
Jan 15, 2021, 3:37:37 AM1/15/21
to
On 14/01/2021 18:38, Rick C wrote:
> I am working on some code to help me design a math circuit in an FPGA and I'm not finding much in the way of display words for double numbers. There is H. in Win32Forth to display a number as hex which I assume is common, but nothing for double numbers. Would DH. be appropriate nomenclature? Or HD. ?
>
> This word actually prints an underscore every four digits so not strictly like D. or H. Is there a naming convention for that sort of thing, like separators every three digits in decimal numeric displays?
>
> : dh. ( d - )
> base @ -rot #16 base !
> <# 0 begin -rot # 2dup D0= 0= while
> rot 1+ dup 4 mod 0= if '_' hold then repeat
> drop s" 0x" holds #>
> type base ! ;
>
> In case anyone is interested. I'd also welcome comments on the code.
>

Nothing wrong with your code but I'd rather use the R stack instead of
ROT and -ROT. Also 3 AND instead of 4 MOD. HEX is a standard word.

: dh. ( d - )
base @ >r hex <# 0
begin
>r # 2dup or
while
r> 1+ dup 3 and 0= if '_' hold then
repeat
s" 0x" holds #> type
2r> drop base !
;

If you want a standard Forth prefix you could do
'$' HOLD instead of S" 0X" HOLDS

--
Gerry

Wolfgang Allinger

unread,
Jan 15, 2021, 5:06:25 AM1/15/21
to

On 14 Jan 21 at group /comp/lang/forth in article cae1b7a8-f492-4b62...@googlegroups.com
<novembe...@gmail.com> (NN) wrote:


> : dh. ( d -- ) hex (h.) decimal ;

is poor code that might break the base, especially with multitasking.

NEVER "do hex ... decimal" BUT "base @ hex ... base !"

> you get the idea.

No, because breaking base :p





Saludos (an alle Vernünftigen, Rest sh. sig)
Wolfgang

--
Ich bin in Paraguay lebender Trollallergiker :) reply Adresse gesetzt!
Ich diskutiere zukünftig weniger mit Idioten, denn sie ziehen mich auf
ihr Niveau herunter und schlagen mich dort mit ihrer Erfahrung! :p
(lt. alter usenet Weisheit) iPod, iPhone, iPad, iTunes, iRak, iDiot

NN

unread,
Jan 15, 2021, 7:12:52 AM1/15/21
to
I have never multi-tasked within forth, its on my to-do list.

NN

unread,
Jan 15, 2021, 7:16:58 AM1/15/21
to
Yes, I tweaked my output because I prefered ':'

Clive Arthur

unread,
Jan 15, 2021, 9:03:19 AM1/15/21
to
On 14/01/2021 18:38, Rick C wrote:
> I am working on some code to help me design a math circuit in an FPGA and I'm not finding much in the way of display words for double numbers. There is H. in Win32Forth to display a number as hex which I assume is common, but nothing for double numbers. Would DH. be appropriate nomenclature? Or HD. ?
>
> This word actually prints an underscore every four digits so not strictly like D. or H. Is there a naming convention for that sort of thing, like separators every three digits in decimal numeric displays?
>
> : dh. ( d - )
> base @ -rot #16 base !
> <# 0 begin -rot # 2dup D0= 0= while
> rot 1+ dup 4 mod 0= if '_' hold then repeat
> drop s" 0x" holds #>
> type base ! ;
>
> In case anyone is interested. I'd also welcome comments on the code.
>

I used hex display a lot years ago when clock cycles mattered.

Take a nibble, if it's >9 then add 7. Then add 0x30 and Emit it. That
way 0..15 becomes ASCII 0..F

Shift and repeat as necessary - look Mum, no division, no base, no pad!

So I ended up with .hex .hexD .hexN as I recall. Putting underscores in
would be trivial, maybe .hex_D or similar.

--
Cheers
Clive

Wolfgang Allinger

unread,
Jan 15, 2021, 10:40:39 AM1/15/21
to

On 15 Jan 21 at group /comp/lang/forth in article ae6afa33-4940-43f0...@googlegroups.com
<novembe...@gmail.com> (NN) wrote:

> On Friday, 15 January 2021 at 10:06:25 UTC, Wolfgang Allinger wrote:
>> On 14 Jan 21 at group /comp/lang/forth in article
>> cae1b7a8-f492-4b62...@googlegroups.com <novembe...@gmail.com> (NN) wrote:
>>
>>
>>> : dh. ( d -- ) hex (h.) decimal ;
>> is poor code that might break the base, especially with multitasking.
>>
>> NEVER "do hex ... decimal" BUT "base @ hex ... base !"
>>
>>> you get the idea.
>>
>> No, because breaking base :p

> I have never multi-tasked within forth, its on my to-do list.

Even with non multitasking, words with hidden sideeffect changing the base
are error prone to other words. And sometimes you spend a lot of time,
chasing such silly code. Just bad coding!

Wolfgang Allinger

unread,
Jan 15, 2021, 10:40:39 AM1/15/21
to

On 15 Jan 21 at group /comp/lang/forth in article rts7b5$19e$1...@dont-email.me
<cl...@nowaytoday.co.uk> (Clive Arthur) wrote:

> I used hex display a lot years ago when clock cycles mattered.

> Take a nibble, if it's >9 then add 7. Then add 0x30 and Emit it. That
> way 0..15 becomes ASCII 0..F

And it exist the DAA assembler code doing that on many uC



> Shift and repeat as necessary - look Mum, no division, no base, no pad!

With DAA you don't need to shift also!


just 4 or even 3 ASSEMBLER codes :)

appended:

----8x----
\ BIN2ASC.txt WALL20210115

REED THIS IN MONOSPACE FONTs !!!

Samples by Dipl.-Ing. Wolfgang Allinger; Villa Elisa, Paraguay
all...@gmx.de

---
all nums are HEX
1.) Default Binary to ASCII Hex conversion --rehash of an old idea

If you've been at this business of assembly programming long enough,
you're sure to have stumbled across this trick for converting a binary
value from 0 to 15 (0Fh) to its ASCII representation ('0'...'F')

(I'll use x86 code):
Code:
; ACC= ACC=
; 0-9: CY AF A-F: CY AF
add al,90h ; 90..99 0 0 9A..9F 0 0
daa ; 90..99 0 0 FA..FF 1 1
adc al,40h ; D0..D9 0 0 3B..40 0 0
daa ; 30..39 '0..9' 41..46 'A..F' BINGO!

This is at least as old as the Intel MDS monitor and probably older
as it can be used on the 8008 too.

---
2.) a better trick
And, if you're like me, you made the transition to x86 carrying this
trick along in your bag of tricks without giving it a second thought.
However, consider this bit of code using DAS:
Code:

cmp al,0ah
sbb al,69h
das

One instruction (and one byte) shorter! I picked this one up out of
an AMD code optimization app note. It should work on a Z80, but not,
of course on an 8080 or 8085, as these lack the DAS instruction.

Saludos y suerte
Wolfgang Allinger

---
Note by Chuck(G); July 26th, 2011 at 12:55 PM.

•The DAA instruction works as follows:
* If the least significant four bits in AL are > 9 or if AF =1,
it adds 06h to AL and sets AF
* If the most significant four bits in AL are > 9 or if CF =1,
it adds 60h to AL and sets CF

•The DAS instruction works as follows:
*If the least significant four bits in AL are > 9 or if AF =1,
it subtracts 06h from AL and sets AF
*If the most significant four bits in AL are > 9 or if CF =1,
it subtracts 60h from AL and sets CF

---
----8x----

Clive Arthur

unread,
Jan 15, 2021, 10:48:03 AM1/15/21
to
On 15/01/2021 15:37, Wolfgang Allinger wrote:
>
> On 15 Jan 21 at group /comp/lang/forth in article rts7b5$19e$1...@dont-email.me
> <cl...@nowaytoday.co.uk> (Clive Arthur) wrote:
>
>> I used hex display a lot years ago when clock cycles mattered.
>
>> Take a nibble, if it's >9 then add 7. Then add 0x30 and Emit it. That
>> way 0..15 becomes ASCII 0..F
>
> And it exist the DAA assembler code doing that on many uC
>
<snip>

Hi Wolfgang

Ain't got no DAA on an RTX2001, but a good method for those crippled
with profane processors.

--
Cheers
Clive

Andy Valencia

unread,
Jan 15, 2021, 11:09:59 AM1/15/21
to
"Wolfgang Allinger" <all...@spambog.com> writes:
> >>> : dh. ( d -- ) hex (h.) decimal ;
> >> is poor code that might break the base, especially with multitasking.

In many tasking systems, base is a USER variable, thus local to that
task.

But yes, saving/restoring is better than assuming you should hard
code where you'll leave it.

Andy Valencia
Home page: https://www.vsta.org/andy/
To contact me: https://www.vsta.org/contact/andy.html

none albert

unread,
Jan 15, 2021, 12:22:43 PM1/15/21
to
In article <8e60b707-cfeb-4467...@googlegroups.com>,
Rick C <gnuarm.del...@gmail.com> wrote:
>I am working on some code to help me design a math circuit in an FPGA
>and I'm not finding much in the way of display words for double numbers.
>There is H. in Win32Forth to display a number as hex which I assume is
>common, but nothing for double numbers. Would DH. be appropriate
>nomenclature? Or HD. ?
>
>This word actually prints an underscore every four digits so not
>strictly like D. or H. Is there a naming convention for that sort of
>thing, like separators every three digits in decimal numeric displays?
>
>: dh. ( d - )
> base @ -rot #16 base !
> <# 0 begin -rot # 2dup D0= 0= while
> rot 1+ dup 4 mod 0= if '_' hold then repeat
> drop s" 0x" holds #>
> type base ! ;
>
>In case anyone is interested. I'd also welcome comments on the code.

This looks so much better with a little bit of factoring.

SCR # 123
0 ( H. B. DH. BASE? HEX: ) \ AvdH B2mar13
1 \ Switch to hex for the duration of the definition.
2 : HEX: R> BASE @ >R >R HEX CO R> BASE ! ;
3 : DEC: R> BASE @ >R >R DECIMAL CO R> BASE ! ;
4 ( Add a , after 4 digits )
5 : 4? 1+ 4 MOD 0= IF &, HOLD THEN ;
6 : 3? 1+ 3 MOD 0= IF &, HOLD THEN ;
7 ( Generate string with hex format of DOUBLE of LEN digits)
8 : (DH.) HEX: <# 1- 0 ?DO # I 4? LOOP # #> ;
9 : B. S>D 2 (DH.) TYPE ; ( print BYTE in hex )
10 : H. S>D 2 CELLS (DH.) TYPE ; ( print SINGLE in hex )
11 : DH. 4 CELLS (DH.) TYPE ; ( print DOUBLE in hex )
12 ( print DOUBLE in decimal )
13 : DEC. 5 CELLS DEC: <# 1- 0 ?DO # I 3? LOOP # #> TYPE ;
14 : BASE? BASE @ B. ; ( 0/0 TRUE VALUE OF BASE)
15 OK

Like so:

12. DEC.
0,000,000,000,000,000,000,000,000,000,000,000,000,012 OK

-12. DH.
FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFF4 OK

I'm aware of the need to have separators but not of any
conventions.

Groetjes Albert




Get 1,000 miles of free Supercharging
>- Tesla referral code - https://ts.la/richard11209
--
This is the first day of the end of your life.
It may not kill you, but it does make your weaker.
If you can't beat them, too bad.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Rick C

unread,
Jan 15, 2021, 1:59:13 PM1/15/21
to
I started out with >R and R>, but it always makes me nervous as it can be problematic if you forget the issues involved while the code is morphing. In fact, I think I mucked up something and crashed Win32Forth that made me want to change it. Why do you prefer the R stack?

Yeah, I suppose 3 AND is faster not requiring a divide.

I thought about the $ prefix rather than the 0x, but I don't work with Forth exclusively and 0x is more natural to me. I'm not expecting to use this to print values to feed back into Forth. But point taken. Thanks

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 15, 2021, 2:02:49 PM1/15/21
to
Ok, got it. Thanks

--

Rick C.

++ Get 1,000 miles of free Supercharging
++ Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 15, 2021, 2:27:51 PM1/15/21
to
Sure, interesting point. I guess hex and octal representations are special cases of the general base oriented output, used exactly because they are special cases, so why not take advantage of that? I was thinking shortest path between two points. Maybe I should take a shot at that and maybe put it in my personal library?

Since the chars have to be printed msd first, how would you shift the data around? It is rather natural to handle the lsd first while awkward to get to the msd first. msd first requires a lot of shifting for every digit. I suppose the hex digits can be picked off lsd first and simply shoved onto the stack, then processed msd first. It's not like there would be tons of them. 32 bit work needs 8 digits, 64 bit word needs 16. Might not work so well on a GA14... but then even double precision is only 9 digits. In that case the word might be split in half to ease the stack burden.

I'm working on an FPGA design using hard IP for the math. Easier to think in Forth than in VHDL so I trying my ideas here. The base word size is 18 bits, but the multiplier is 36x18 producing a 54 bit result. Fortunately Forth is rich with mixed resolution operators and it seems to work out without too much pain in a 32 bit forth. The design does make my head hurt. I think I have lost some abilities over the years. When I was younger I would have been done with this by now. In my defense the docs on the DSP unit are really piss poor. They don't even describe the operation in any detail. I'm having to reverse engineer the simulation code which is intended to handle all of the different configurations. The DSP is basically a MAC and doesn't actually support add/sub, pick one of the two. So either add a controlled complement to the input or just drop the DSP accumulator and code that in the FPGA fabric.

In the end I'll probably have special output words to display formats specific for each stage of the computations. To avoid the hassles of fixed point math I'm making it a 36 bit floating point MAC. Now that I've ditched the DSP accumulator the operation should be simple. I've always found it interesting that the floating point add is more complicated than the floating point multiply because of the need for a barrel shifter to denormalize an operand and to normalize the result. The multiply only ever needs a single bit shift to normalize the result.

--

Rick C.

--- Get 1,000 miles of free Supercharging
--- Tesla referral code - https://ts.la/richard11209

Wolfgang Allinger

unread,
Jan 15, 2021, 3:14:18 PM1/15/21
to

On 15 Jan 21 at group /comp/lang/forth in article rtsdfh$f79$1...@dont-email.me
<cl...@nowaytoday.co.uk> (Clive Arthur) wrote:

> On 15/01/2021 15:37, Wolfgang Allinger wrote:
>>
>> On 15 Jan 21 at group /comp/lang/forth in article
>> rts7b5$19e$1...@dont-email.me <cl...@nowaytoday.co.uk> (Clive Arthur) wrote:
>>
>>> I used hex display a lot years ago when clock cycles mattered.
>>
>>> Take a nibble, if it's >9 then add 7. Then add 0x30 and Emit it. That
>>> way 0..15 becomes ASCII 0..F
>>
>> And it exist the DAA assembler code doing that on many uC
>>
> <snip>

> Ain't got no DAA on an RTX2001, but a good method for those crippled
> with profane processors.

I did a lot with RTX2001 :) I love this Processor.

But when Harris run it down, I switched to SIEMENS C166 Family for fast
realtime applications.

It has about 66% of RTX speed for SW, but lots of excellent HW on chip,
Timers with capture compare eg. so for HW performance it wasn't slower
than the RTX.

On RTX you need a lot of little SW routines for what the HW of the C166
can handle naturely. So I didn't miss the RTX really. I had a Metacompiler
from LMI for this little beast :)

Don't know if the C166/167 family exists any longer. But it was used in
the German Industrie very heavy :) Yes I'm feeling culprit for that :)

My last C166/167 Project was about 2003.
It was a very fast controller for V10 high performance gasolin engine.
much above 500hp.

I signed a NDA :] not with Mercedes, but same city :)

Gerry Jackson

unread,
Jan 15, 2021, 4:07:25 PM1/15/21
to
Fewer stack operations so more efficient, although a code optimiser
might make it less so.


--
Gerry

Rick C

unread,
Jan 15, 2021, 4:45:06 PM1/15/21
to
Yeah, it takes a lot of stack ops to fill the time spent dealing with a single error message cause by an errant return stack usage. I don't avoid them like the plague, but I don't use them unless there is a clear advantage. I have no grudge against ROT. In fact it's a nice little word. Very cute.

--

Rick C.

--+ Get 1,000 miles of free Supercharging
--+ Tesla referral code - https://ts.la/richard11209

dxforth

unread,
Jan 16, 2021, 12:43:18 AM1/16/21
to
You've not heard of CSV ? I've not heard of decimals prefixed with 0's :)

Paul Rubin

unread,
Jan 16, 2021, 12:59:20 AM1/16/21
to
Rick C <gnuarm.del...@gmail.com> writes:
>
> : dh. ( d - )
> base @ -rot #16 base !
> <# 0 begin -rot # 2dup D0= 0= while
> rot 1+ dup 4 mod 0= if '_' hold then repeat
> drop s" 0x" holds #>
> type base ! ;
>
> In case anyone is interested. I'd also welcome comments on the code.

1. Doing all that stuff with the double word instead of factoring into a
word to print a single in hex, then doing the double as two singles,
seems un-Forthlike to me.

2. Gforth doesn't have HOLDS so I couldn't directly test your code.

3. If you're using a minimal Forth you might not have that <# formatted
output stuff at all, so you have to do everything from scratch.

Here is my version, assumes 32-bit cells but you can adjust accordingly:

s" 0123456789ABCDEF" ( a u ) drop constant hexdigits
: print-nibble ( n -- ) \ print lower 4 bits of n as a hex digit
$0F and hexdigits + c@ emit ;
: push-nibble ( n -- n n>>4 ) dup 4 rshift ;
: push-16 ( n -- n n>>4 n>>8 n>>12 ) push-nibble push-nibble push-nibble ;
: print-16 ( n -- ) \ print n as 16 bit hex number
push-16 print-nibble print-nibble print-nibble print-nibble ;
: delim ( -- ) '_' emit ;
: print-32 ( n -- ) \ print 32-bit n as two 16 bit hex numbers
dup 16 rshift print-16 delim print-16 ;
: dprint ( d -- ) swap print-32 bl emit print-32 ;

: test ( -- ) $12345678 print-32 cr
$12345678 $23456789 dprint cr ;

Bernd Linsel

unread,
Jan 16, 2021, 2:58:40 AM1/16/21
to
On 15.01.2021 10:55, Wolfgang Allinger wrote:
>
> On 14 Jan 21 at group /comp/lang/forth in article cae1b7a8-f492-4b62...@googlegroups.com
> <novembe...@gmail.com> (NN) wrote:
>
>
>> : dh. ( d -- ) hex (h.) decimal ;
>
> is poor code that might break the base, especially with multitasking.
>
> NEVER "do hex ... decimal" BUT "base @ hex ... base !"
>
>> you get the idea.
>
> No, because breaking base :p
>

Still better: Use CATCH in order to prevent inadvertent exceptions
leaving BASE unchanged. Some years ago, BASE-EXECUTE spooked around clf
(I dimly remember it's built into gforth):

: base-execute ( i*x xt u -- j*y)
base @ >R base ! catch ;


With that, D_H. top level becomes:

: D_H. ( d --) ['] (D_H.) $10 base-execute ;


Bernd Linsel

unread,
Jan 16, 2021, 3:12:30 AM1/16/21
to
Sorry, forgot the important part:

: base-execute ( i*x xt u -- j*y)
base @ >R base ! catch R> base ! ;
^^^^^^^^^

Shame on me...


Anton Ertl

unread,
Jan 16, 2021, 4:12:37 AM1/16/21
to
Paul Rubin <no.e...@nospam.invalid> writes:
>2. Gforth doesn't have HOLDS so I couldn't directly test your code.

The development version has it since at least 2010-02-14. Time to get
the release out:-).

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2020: https://euro.theforth.net/2020

Bernd Linsel

unread,
Jan 16, 2021, 4:25:05 AM1/16/21
to
On 15.01.2021 20:27, Rick C wrote:
> On Friday, January 15, 2021 at 9:03:19 AM UTC-5, Clive Arthur wrote:
>> On 14/01/2021 18:38, Rick C wrote:
>>> I am working on some code to help me design a math circuit in an FPGA and I'm not finding much in the way of display words for double numbers. There is H. in Win32Forth to display a number as hex which I assume is common, but nothing for double numbers. Would DH. be appropriate nomenclature? Or HD. ?
>>>
>>> This word actually prints an underscore every four digits so not strictly like D. or H. Is there a naming convention for that sort of thing, like separators every three digits in decimal numeric displays?
>>>
>>> : dh. ( d - )
>>> base @ -rot #16 base !
>>> <# 0 begin -rot # 2dup D0= 0= while
>>> rot 1+ dup 4 mod 0= if '_' hold then repeat
>>> drop s" 0x" holds #>
>>> type base ! ;
>>>
>>> In case anyone is interested. I'd also welcome comments on the code.
>>>
>> I used hex display a lot years ago when clock cycles mattered.
>>
>> Take a nibble, if it's >9 then add 7. Then add 0x30 and Emit it. That
>> way 0..15 becomes ASCII 0..F
>>
>> Shift and repeat as necessary - look Mum, no division, no base, no pad!
>>
>> So I ended up with .hex .hexD .hexN as I recall. Putting underscores in
>> would be trivial, maybe .hex_D or similar.
>
> Sure, interesting point. I guess hex and octal representations are special cases of the general base oriented output, used exactly because they are special cases, so why not take advantage of that? I was thinking shortest path between two points. Maybe I should take a shot at that and maybe put it in my personal library?
>
> Since the chars have to be printed msd first, how would you shift the data around? It is rather natural to handle the lsd first while awkward to get to the msd first. msd first requires a lot of shifting for every digit. I suppose the hex digits can be picked off lsd first and simply shoved onto the stack, then processed msd first. It's not like there would be tons of them. 32 bit work needs 8 digits, 64 bit word needs 16. Might not work so well on a GA14... but then even double precision is only 9 digits. In that case the word might be split in half to ease the stack burden.

Here is a version completely doing without BASE (since conversion into
base 16 is really trivial) and still using the HOLD buffer instead of
messing around to reverse the digit order.

\ prefix for hex numbers

S" 0x" 2constant hex-prefix ( -- caddr u)

\ hex number grouping char
\ if 0, no grouping char is printed

'_' constant hex-groupchar ( -- ch )


\ converts lowest nibble of u1 into a base-16 digit ch,
\ leaving u2>>4

1 [if]
\ branchless version

: (#H) ( u1 -- u2 ch)
dup 4 rshift swap $f and
'0' + \ 0..15 -> '0'..'?'
dup '9' > [ 'A' ':' - ] literal \ 0 | 'A'-':'
and + ; \ '0'..'9', 'A'..'F'


[else]
\ version with branch instead of bit-fiddling
\ just test which version fits your forth better

: (#H) ( u1 -- u2 ch)
dup 4 rshift swap $f and
dup 9 <= if '0' else [ 'A' 10 - ] then + ;

[then]


\ convert a cell u1 to a string caddr u2 in base 16
\ separate 16-bit-words by hex-groupchar
\ uses the hold buffer

: >H$ ( u1 -- caddr u2)
<#
(#H) hold (#H) hold (#H) hold (#H) hold
hex-groupchar ?dup if hold then
(#H) hold (#H) hold (#H) hold (#H) hold
0 #> ;


\ output d in hex, prefixed by hex-prefix, 16 bit groups
\ separated by hex-groupchar

: D_H. ( d --)
hex-prefix type
>H$ type \ high-part first
hex-groupchar ?dup if emit then \ group char
>H$ type \ low-part second
;

1 [if]
marker hex-printing-test

: test-hex-printing
$98765432 >H$ type cr
3405691582 3735928559 D_H.
;
[then]

dxforth

unread,
Jan 16, 2021, 8:47:59 PM1/16/21
to
On 16/01/2021 16:59, Paul Rubin wrote:
>
> 3. If you're using a minimal Forth you might not have that <# formatted
> output stuff at all, so you have to do everything from scratch.
>

Perhaps why Colorforth never took off

none albert

unread,
Jan 17, 2021, 6:15:58 AM1/17/21
to
In article <87pn25q...@nightsong.com>,
Paul Rubin <no.e...@nospam.invalid> wrote:
>3. If you're using a minimal Forth you might not have that <# formatted
>output stuff at all, so you have to do everything from scratch.

The #-stuff consists of <# # #S HOLD #> and the variable HLD.
These are one liners. A Forth that misses those is not
minimal, but crippled, and probably a toy Forth that is not
even used by its creator.
The design effort is zero because you can just copy them from
figForth or any successor.

One can argue that forcing the use of doubles makes no sense in a
64 bit Forth. So much is sure that a 16 bit Forth without doubles
cannot be used for serious purposes like "the price of real estate
in California" to quote from a very old article in Forth Dimensions.

"yourforth" is 32+ bit. There I did not really remove the # stuff.
I replaced it by single precious equivalent % stuff.

Groetjes Albert
--
in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 LOL, duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Gerry Jackson

unread,
Jan 17, 2021, 9:19:17 AM1/17/21
to
On 17/01/2021 11:15, albert wrote:

> "yourforth" is 32+ bit. There I did not really remove the # stuff.
> I replaced it by single precious equivalent % stuff.
>

IIRC yourforth is a better Jones Forth. Where can it be downloaded. When
I googled it there were loads of messages about removing malware called
yourforth. That seems an unfortunate clash of names


--
Gerry

none albert

unread,
Jan 17, 2021, 11:55:03 AM1/17/21
to
In article <ru1h14$4eh$1...@dont-email.me>,
Unfortunate, or intentional? Why would one call malware yourforth?
Anyway. I've completely forgotten where I published it.
I google yourforth.fas and low and behold, some michal cloned the git archive,
from where I don't know, but it is certainly original.
This michal guy did add a small contribution, an extra comment possibility.
So you can get yourforth here:

https://github.com/tangentstorm/yourforth

P.S.
It is better than jonesforth in one respect at least, it contains
no gratuitous deviations from ISO. It also contains exercises, but
I'm in now way convinced that makes it superior to jonesforth.

(Don't worry, the original is safe in my CVS repository.)

>--
>Gerry

Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Jan Coombs

unread,
Jan 17, 2021, 12:56:11 PM1/17/21
to
On 17 Jan 2021 16:44:26 GMT
albert@cherry.(none) (albert) wrote:

> Anyway. I've completely forgotten where I published it.


Maybe this one?

albert horst Untitled project yourforth
Last commit 2013‑10‑23
https://bitbucket.org/avanderhorst/yourforth/src/master/

Jan Coombs
--

none albert

unread,
Jan 17, 2021, 1:40:31 PM1/17/21
to
In article <20210117175609.7bc66723@t530>,
Thanks! Now that is not easy to find.
I have spent the last few hours looking into old c.l.f discussions,
and the best I could find was my remark:
"just look in the cloud"
That may have worked before the virus came along.
I'm going to move it to github alongside my other projects.

>
>Jan Coombs
>--

Hugh Aguilar

unread,
Jan 17, 2021, 7:43:43 PM1/17/21
to
Rick Collins has been struggling to figure out how to print hex numbers since at least 2015.
We had this example of using a flag as a mask was given (modified slightly here to make it ANS-Forth):

: >CHAR ( [0,15] -- char )
DUP 9 > 7 AND + [CHAR] 0 + ;

A Forther (Hans Bezemer) complained that this code is bad style,
and the Forth-200x committee-member Bernd Payson defended it:

On Sunday, May 24, 2015 at 5:21:05 PM UTC-7, Bernd Paysan wrote:
> Hans Bezemer wrote:
> > ...True, it
> > is a clever piece of programming, but in our opinion it is bad
> > style. Why? Because you are using a flag as a bitmask, which is a
> > completely different datatype. Although there is no such thing as
> > “data typing” in Forth, this way of programming makes it
> > difficult to understand and maintain a program, which the
> > ANS-Forth standard acknowledges:
>
> Honestly, this is only a problem if you don't know that idiom. A lot of
> people don't know that you can use masks and logical operations, so they
> will find that operation strange.
> ...
> Therefore, I would reiterate what I told Hugh some times: If you don't know
> something, it's *not* the fault of the person who uses and knows that thing.
> It's entirely your fault, and if you want to be a wise person, you'd rather
> learn it that complain.
>
> IMHO the whole datatype based thinking about cells in Forth is ill-advised.
> First, and foremost, a cell is a bit pattern, and if you add and subtract
> it, it's a mod 2^n ring. You can use that to some degrees as integer, but
> it's not an integer. It's a cell.
>
> --
> Bernd Paysan
> "If you want it done right, you have to do it yourself"

Elizabeth Rather responded:

> Thank, you, Bernd, well-said.
>
> Cheers,
> Elizabeth

A little later we had this:

On Tuesday, May 26, 2015 at 11:37:37 AM UTC-7, Elizabeth D. Rather wrote:
> On 5/26/15 8:15 AM, rickman wrote:
> > On 5/26/2015 1:20 PM, WJ wrote:
> >> That code is unreadable and unmaintainable. It's very hard
> >> to figure out how it accomplishes its task. I would not
> >> pay a programmer to produce code like that.
> >>
> >> This is somewhat more understandable:
> >>
> >> : >char
> >> dup 9 > if [char] A 10 - else [char] 0 then
> >> + ;
> >
> > If you have any reason to look at the definition of >char then I can't
> > see how you would not understand how it works. Perhaps this would be a
> > better definition...
> >
> > \ Convert n to ASCII char
> > : >CHAR ( n -- char ) DUP 9 > 7 AND + ASCII 0 + ;
> >
> > Lol, saying it is unreadable and unmaintainable is a bit of a stretch. I
> > think that exact code has been read and understood as well as maintained
> > for many years now. I am pretty sure I have seen something similar to
> > it way back when I was learning assembly language. I think it took me
> > two minutes to see what it was doing.
>
> Indeed, proper documentation as in rickman's version above is essential
> to readable & maintainable code. Neither of the previous versions is
> acceptable, although I find the shorter code quite clear (and, as
> rickman notes, it's been around for many years). I would have preferred
> [CHAR] instead of ASCII, however, as it's Standard.
>
> Cheers,
> Elizabeth

It is not really that I (Hugh Aguilar, slammed by Bernd Payson for being unwise) don't know how to
use a flag as a mask in logic-arithmetic --- it is just that I don't want to --- this is my own code
(written in ANS-Forth, and one of the previous versions mentioned above as not being acceptable):

: indexed-char \ index adr cnt -- char \ the string will be used as an array of chars
rover 0< abort" *** INDEXED-CHAR given a negative index ***"
rover <= abort" *** INDEXED-CHAR given an index too large ***"
+ c@ ;

: hexit>char \ [0,15] -- char
s" 0123456789ABCDEF" indexed-char ;

This is an example of how I relate to Forth differently from most ANS-Forth and Forth-200x enthusiasts
(I'm one of the few people on the planet who has had a paying job writing Forth code).
I consider >CHAR above to be tricky code (the 7 is a "magic number" that is only going to be meaningful
to somebody who has memorized the ascii character set) --- these kinds of tricks were done
in the 1970s when programmers' primary goal was to save memory.

Hugh Aguilar

unread,
Jan 17, 2021, 8:36:12 PM1/17/21
to
On Friday, January 15, 2021 at 9:09:59 AM UTC-7, Andy Valencia wrote:
> "Wolfgang Allinger" <all...@spambog.com> writes:
> > >>> : dh. ( d -- ) hex (h.) decimal ;
> > >> is poor code that might break the base, especially with multitasking.
> In many tasking systems, base is a USER variable, thus local to that
> task.
>
> But yes, saving/restoring is better than assuming you should hard
> code where you'll leave it.

Rick Collins is programming Forth at the kindergarten level, struggling to
convert a number into a string, and he has been at this level for a long time.

Even kindergarten-level Forth is complicated in ANS-Forth though.
Elizabeth Rather did not include USER variables in ANS-Forth,
most likely because she didn't understand multi-tasking.

Also, ANS-Forth relies on static memory buffers for <# #> data,
and for WORD, and for PAD that I consider to be the hallmark of ANS-Forth.
This is retarded! Once again, this is a failure to understand reentrancy.

Here is an example of ANS-Forth code in VFX:
------------------------------------------------------------------
: test 0 <# #S #> ; ok
123 test type 123 ok
456 test ok-2
type 452 ok
------------------------------------------------------------------
It types out 452 rather than 456 because the 2 in the "ok-2" message overwrites
the <# #> static memory buffer. LOL

Of course, I fix all of these idiotic problems in the novice package:
------------------------------------------------------------------
: test 0 <# #S #> ;
TEST is redefined ok
123 test type 123 ok
456 test ok-2
type 456 ok
------------------------------------------------------------------

Being an ANS-Forth programmer primarily involves working around
Elizabeth Rather's idiotic mistakes in designing ANS-Forth.
Stephen Pelc hasn't succeeded at this, as he still has multiple bugs
in VFX due to his failure to understand the bugs in ANS-Forth and fix them.

dxforth

unread,
Jan 18, 2021, 5:54:11 PM1/18/21
to
Correct - VFX fails as a novice support package. It underappreciates
the extent to which novices need molly-coddling.

NN

unread,
Jan 19, 2021, 9:31:04 AM1/19/21
to
On Friday, 15 January 2021 at 10:06:25 UTC, Wolfgang Allinger wrote:
> On 14 Jan 21 at group /comp/lang/forth in article cae1b7a8-f492-4b62...@googlegroups.com
> <novembe...@gmail.com> (NN) wrote:
>
>
> > : dh. ( d -- ) hex (h.) decimal ;
> is poor code that might break the base, especially with multitasking.
>
> NEVER "do hex ... decimal" BUT "base @ hex ... base !"
>
> > you get the idea.
>
> No, because breaking base :p
>
>
>
>
>
> Saludos (an alle Vernünftigen, Rest sh. sig)
> Wolfgang
>
> --
> Ich bin in Paraguay lebender Trollallergiker :) reply Adresse gesetzt!
> Ich diskutiere zukünftig weniger mit Idioten, denn sie ziehen mich auf
> ihr Niveau herunter und schlagen mich dort mit ihrer Erfahrung! :p
> (lt. alter usenet Weisheit) iPod, iPhone, iPad, iTunes, iRak, iDiot


I have thought about this and given the context of the question, I think the
simplest solution is better.

Which leads me to ask a further question to anyone reading,
are there any forthers who will confess to doing any multitasking forth programming.

I dont mean windows ( or other OS ) multitasking but forth multitasking. I have
assumed the two are mutually exclusive but if thats wrong please let me know.

I am curious about the numbers.

Brian Fox

unread,
Jan 19, 2021, 10:06:59 AM1/19/21
to
On 2021-01-19 9:31 AM, NN wrote:

> Which leads me to ask a further question to anyone reading,
> are there any forthers who will confess to doing any multitasking forth programming.
>

I have written two applications where I used Forth multi-tasking.
This was in the 1990s however. Seems like the stone age now.

One was a data entry terminal for a Television Telethon (money raising
event on TV). The receipts were gathered up from the telephone desk
and given to the data entry person. They entered the name and
amount of each donation into a Forth database that used blocks.
A background task read the database like a circular queue and sent the
data over RS-232 to a modem that connected via another modem to
the Chyron TV character generator computer. This generated a continuous
"crawl" of text which was super-imposed on the TV picture during the
broadcast.

I remember someone at the hospital asking me what O/S the terminal was
using. I said MS DOS. He said " You can't do that with DOS!"
This app used HsForth but I had modified the multi-tasking system to
make it multi-user.

The 2nd application counts newly hatched chicks at 60,000 per hour and
puts them in boxes of 100.
It has a robotics control task, a user keyboard and plasma display task
and a RS-232/488 remote access task.
The counter is running on an timer interrupt every 4 mS. The other
tasks are cooperative. This uses MaxForth.


Andy Valencia

unread,
Jan 19, 2021, 10:13:44 AM1/19/21
to
NN <novembe...@gmail.com> writes:
> Which leads me to ask a further question to anyone reading, are
> there any forthers who will confess to doing any multitasking forth
> programming.

Sure, I use multiple terminals (F1..F4 by default switch between
the sessions), native tasking entirely written in Forth:

http://sources.vsta.org/forthos/

Each CLI context gets its own memory allocation, so typically
you'll load/forget/reload on the first screen, and use the others
to view source, try things interactively, view data structures,
and things like that.

Stephen Pelc

unread,
Jan 19, 2021, 11:04:20 AM1/19/21
to
On Tue, 19 Jan 2021 06:31:02 -0800 (PST), NN
<novembe...@gmail.com> wrote:

>Which leads me to ask a further question to anyone reading,=20
>are there any forthers who will confess to doing any multitasking forth pro=
>gramming.
>
>I dont mean windows ( or other OS ) multitasking but forth multitasking. I=
> have=20
>assumed the two are mutually exclusive but if thats wrong please let me kno=
>w.

Why are the two mutually exclusive and what is Forth multi-tasking?

The usual problem is that most modern operating systems use a
pre-emptive scheduler and the "traditional" Forth scheduler is
cooperative.

MPE's desktop systems use the O/S scheduler, and our embedded
systems use a cooperative scheduler. Despite this, the two wordsets
used to control tasking are virtually identical.

Virtually everyting I have written for the last 20 years or so has
used tasks, not least because I want a Forth interactive console
available at any time. If you are using non real-time comms such as
TCP/IP or USB or radio, you will need tasks.

Stephen

--
Stephen Pelc, ste...@vfxforth.com <<< NEW
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, +44 (0)78 0390 3612
web: http://www.mpeforth.com - free VFX Forth downloads

none albert

unread,
Jan 19, 2021, 12:52:42 PM1/19/21
to
In article <8f18b417-a028-4a0c...@googlegroups.com>,
If you want to use 8 cores, it makes no sense to do cooperative multi-tasking.
I use ciforth's preemptive multitasking, i.e. real OS processes to speed up
prime counting by a factor of 6 or so.

The program manx that play music on instruments real time has a complicated
cooperative scheduling. The lowest priority is the keyboard. The next priority
is the playing of parts that fills queues for the musical events. Each Parts
instrument has its own task at this level.
The musical events are scheduled with submillisecond precision, and have
the highest priority. Still the system is responsive because musical events
allow gaps of several milliseconds. This prevents Linux from descheduling
the Forth that runs the manx.

NN

unread,
Jan 19, 2021, 1:18:22 PM1/19/21
to
Am I correct to assume that when you say natively tasking
its what others refer to as cooperative ?

I will have to check out the source. Thanks for posting this stuff online.

Rick C

unread,
Jan 19, 2021, 2:45:40 PM1/19/21
to
On Tuesday, January 19, 2021 at 9:31:04 AM UTC-5, NN wrote:
> On Friday, 15 January 2021 at 10:06:25 UTC, Wolfgang Allinger wrote:
> > On 14 Jan 21 at group /comp/lang/forth in article cae1b7a8-f492-4b62...@googlegroups.com
> > <novembe...@gmail.com> (NN) wrote:
> >
> >
> > > : dh. ( d -- ) hex (h.) decimal ;
> > is poor code that might break the base, especially with multitasking.
> >
> > NEVER "do hex ... decimal" BUT "base @ hex ... base !"
> >
> > > you get the idea.
> >
> > No, because breaking base :p
> >

> I have thought about this and given the context of the question, I think the
> simplest solution is better.

And what solution would that be exactly?


> Which leads me to ask a further question to anyone reading,
> are there any forthers who will confess to doing any multitasking forth programming.
>
> I dont mean windows ( or other OS ) multitasking but forth multitasking. I have
> assumed the two are mutually exclusive but if thats wrong please let me know.
>
> I am curious about the numbers.

No, I've not done multitasking unless you mean working with interrupts which I also would say no to in terms of programming in Forth. Interrupt routines typically are coded in assembly... which on a stack machine still is assembly and not really Forth.

--

Rick C.

-+- Get 1,000 miles of free Supercharging
-+- Tesla referral code - https://ts.la/richard11209

Wolfgang Allinger

unread,
Jan 19, 2021, 4:35:46 PM1/19/21
to

On 19 Jan 21 at group /comp/lang/forth in article a83a1079-02e1-4caa...@googlegroups.com
No, long time ago I programmed several multitasking systems for some dozen
different customers. It was a cooperative multitasking under F-PC running
on MS-DOS or WindowsXP. I had an own TSR IR package for 1ms Timer
resolution and 16 timers and 16 tickers underlaying, which could be called
by the F-PC main application/tasker. As Steven wrote: one task was my
beloved Forth console, so I could watch anything, what's goning on and
start/stop test/documentation tasks while not disturbing the main process.

Anyhow, some slow IR services are written in HLL ( :-def ), others in sub
1ms are written in CODE-def.

I coded all ( asynchronous IR service) in :, just to learn (interactively)
whats going on. Then profiling, which words are too slow for realtime and
recoded them in CODE. Easy as an code-monkey, no worry about anything,
because I have e running, debugged COLON, just recode it. Both defs (:
code ) in a testloop comparing the results. If there are some
discrepancies, correct the CODE.

I improved the F-PC multitasker and debugged it and make it "ABORT" proof.
All the gurus told me(1), that that is impossible. And so nobody took
notice of my extensions in clf :(

One system was running on (Industrie) PC Basis one of my customer untill
2013(?) and went't out of service after 20 years without any hitch. Yes
with 1ms resolution for the timings of a testing machine.
Another based on 2 80C196 for 15yrs.

---
(1) I'm an old really hardcore assembler and a realtime programmer in the
0,1ms realm and up to 20 tasks and 15 different IR service levels, even on
a PC :) At 1984(?) I was fixed as Forth Junky :)

High end with RTX2000 each 500kHz IR frequency!!! extreme realtime!
With a total of some 40+ RTX2000 boards in a single testing machine.

Some of my SW/HW was TÜV certified for Nuclear Power Plant.

Andy Valencia

unread,
Jan 19, 2021, 5:07:16 PM1/19/21
to
NN <novembe...@gmail.com> writes:
> Am I correct to assume that when you say natively tasking
> its what others refer to as cooperative ?

Yes, ForthOS runs on the bare metal, and the tasking is cooperative.
Its earliest guts are from the famous Dr. Ting's eForth.

dxforth

unread,
Jan 19, 2021, 11:01:27 PM1/19/21
to
On 20/01/2021 01:31, NN wrote:
>
> Which leads me to ask a further question to anyone reading,
> are there any forthers who will confess to doing any multitasking forth programming.
>

No, though I include a demo to verify the multitasker works.
Coincidentally it also demonstrates printing hex and decimal numbers
without having to save/restore BASE :)

\\ Demo 1
variable SCREEN screen off

#user dup user CNT 1 cells +
( u) dup 128 64 tcb DCOUNTING \ task1 control block
( u) 128 64 tcb HCOUNTING \ task2 control block

: DCOUNTER ( -- ) dcounting activate decimal 0 cnt !
begin screen get 0 2 at-xy cnt @ dup 0 10 d.r
1+ cnt ! screen release pause again ;

: HCOUNTER ( -- ) hcounting activate hex 0 cnt !
begin screen get 15 2 at-xy cnt @ dup 0 10 d.r
1- cnt ! screen release pause again ;

: RUN ( -- ) /tasker page ." 2 tasks counting:"
dcounter hcounter multi begin key? until key drop single ;

cr .( Save demo1? ) y/n [if] turnkey run DEMO1 bye [then]

Mike

unread,
Jan 20, 2021, 12:01:04 AM1/20/21
to
On Tuesday, January 19, 2021 at 4:31:04 PM UTC+2, NN wrote:
>
> I dont mean windows ( or other OS ) multitasking but forth multitasking. I have
> assumed the two are mutually exclusive but if thats wrong please let me know.

It is very useful to have the Forth console available to interactively test and observe the system,
while the application is running in the background.

I am usually running my embedded applications in background co-operative Forth tasks.
These are soft realtime applications, with sleep possibility between the system ticks in order to save power.

For example now I have a PIC18F46k83 with FlashForth on my table with 2 background tasks.
One task for excuting the A/D stuff and the BMS state machine, and another task for sending
messages to the NMEA2000 CAN bus.

Alexander Wegel

unread,
Jan 20, 2021, 3:43:21 AM1/20/21
to
Hugh Aguilar <hughag...@gmail.com> wrote:

> It is not really that I (Hugh Aguilar, slammed by Bernd Payson for being
> unwise) don't know how to use a flag as a mask in logic-arithmetic --- it
> is just that I don't want to --- this is my own code (written in ANS-Forth,
> and one of the previous versions mentioned above as not being acceptable):
>
> : indexed-char \ index adr cnt -- char
> \ the string will be used as an array of chars
> rover 0< abort" *** INDEXED-CHAR given a negative index ***"
> rover <= abort" *** INDEXED-CHAR given an index too large ***"
> + c@ ;
>
> : hexit>char \ [0,15] -- char
> s" 0123456789ABCDEF" indexed-char ;
>
> This is an example of how I relate to Forth differently from most ANS-Forth
> and Forth-200x enthusiasts

It's inefficient, doing a lot of superfluous checking and juggling. As
Hugh Aguilar would say: "you screwed it up".

NN

unread,
Jan 20, 2021, 8:24:23 AM1/20/21
to
Therein lies the problem ....

the question should really be is the function giving the correct output in the
environment its being used ?

What you might consider inefficient for your use , might be perfectable for
someone else.

The programmer can always come back at a later stage and rewrite it should
the need arise.

So was the function correct ?

dxforth

unread,
Jan 21, 2021, 3:15:35 AM1/21/21
to
I can imagine an ascii to binary routine potentially requiring checks,
but not the reverse.


Rick C

unread,
Jan 21, 2021, 4:18:20 AM1/21/21
to
Sure, the way this routine is written anything outside the range of 0-15 will cause an access outside the declared array resulting in an ambiguous condition. Either flag the error or the bits of interest should be masked off first to preclude the error. As written the calling routine would need to do the masking.

--

Rick C.

-++ Get 1,000 miles of free Supercharging
-++ Tesla referral code - https://ts.la/richard11209

dxforth

unread,
Jan 21, 2021, 6:19:31 AM1/21/21
to
The calling routine will never send more than a nibble of data at a time
(what it was designed to do).


NN

unread,
Jan 21, 2021, 6:32:43 AM1/21/21
to
Can you give an example of an ambigious condition?

NN

unread,
Jan 21, 2021, 6:36:20 AM1/21/21
to
Thats a different question.


NN

unread,
Jan 21, 2021, 8:17:14 AM1/21/21
to
Let me rephrase that -- can you give me an example where the function as given above produces an ambigious condition

Hugh Aguilar

unread,
Jan 21, 2021, 1:05:04 PM1/21/21
to
Here is a lengthy and amusing thread:
https://groups.google.com/g/comp.lang.forth/c/92KNs8p4J6Y/m/ISU4BC_yFgAJ
Alex Wegel attacks me for my late-binding MACRO: then attacks me for my
early-binding MACRO: when I write that. There are only two kinds of macros,
which are late-binding and early-binding, and I got attacked for both, indicating
that there is nothing I can do in which I won't get attacked.
Note that Alex Wegel has not succeeded at writing either kind of macro.

Also note that I had an early-binding MACRO: written in UR/Forth at Testra,
but I got attacked by Anton Ertl for porting this to ANS-Forth in 2009 because
FIND of semicolon crashes gForth, which he thinks I should have predicted.
It was only after I wrote all of the disambiguifiers that I was able to port the
early-binding MACRO: from Forth-83 to ANS-Forth, but Stephen Pelc now attacks me
for my disambiguifiers:
https://groups.google.com/g/comp.lang.forth/c/T-yYkpVwYew/m/C6uvd8djAgAJ
In this thread I also comment on Anton Ertl's ridiculous ]] word that totally fails
on any word that extracts data from the input stream, and also on literals.

This business of converting a nybble into an ascii char, as done by my
INDEXEC-CHAR and HEXIT>CHAR is kindergarten-level Forth that I would expect
anybody with one week of Forth experience to succeed at (Rick Collins has been
struggling with this since at least 2015, and Bernd Paysan calls me "unwise" for
succeeding, which Elizabeth Rather 100% agreed with). So, I not only get attacked
for writing MACRO: (at least intermediate-level Forth) but also for writing this
kindergarten-level Forth.

This is why nobody wants to be an ANS-Forth programmer.
The ANS-Forth cult do nothing but attack, attack, attack!
Anybody who writes Forth code from novice-level to intermediate-level to
advanced-level (my MFX) will get attacked by the ANS-Forth cult for doing so.

Rick C

unread,
Jan 21, 2021, 3:26:33 PM1/21/21
to
Lol! Yes, and if everything in coding went according to plan... The point is that code flags mistakes rather than letting them ferment dissent within the application resulting in an array of symptoms (pun intended) with no clear connection to the cause.

You may feel it is superfluous but that is matter of programming style.

--

Rick C.

+-- Get 1,000 miles of free Supercharging
+-- Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 21, 2021, 3:27:42 PM1/21/21
to
I believe the Forth standard defines the term. Or are you asking something else?

--

Rick C.

+-+ Get 1,000 miles of free Supercharging
+-+ Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 21, 2021, 3:37:03 PM1/21/21
to
GG may have lost my post, so I'm repeating it.

I think the example would be obvious. 99 hexit>char This would cause a memory access outside of the intended array resulting in an invalid character being returned or possibly a memory protection violation resulting in an application crash.

But that's not what you are asking is it? What is your real question?

--

Rick C.

++- Get 1,000 miles of free Supercharging
++- Tesla referral code - https://ts.la/richard11209

NN

unread,
Jan 21, 2021, 4:48:36 PM1/21/21
to
Have you tried executing the function in a real forth ?
If yes, what made you choose 99 as an argument ?

Rick C

unread,
Jan 21, 2021, 6:33:42 PM1/21/21
to
Do you understand what I am saying? I don't understand the point of your questions. Neither are relevant to the issue of the functioning of the code being discussed. The code in question, + c@ is simple enough to understand how it works and what it will do that I don't need to test it.

One thing I thought was missing was an acknowledgement of the varied addressing on different machines by using CHARS + rather than just +. Hugh, the author of the code, typically feels no need to make the same generalizations as the Forth standard committee, so this is the sort of thing he would omit and that's fine for what he does. Rather than limit my code to more conventional computers and in particular because a lot of my code is for custom hardware that is purpose built rather than adhering to any convention, I would use CHARS + since in the worst case CHARS becomes a noop. In the best case it allows code to run on a machine that otherwise would need to be rewritten.

I would ask you to try to say something rather than simply continuing to ask questions. I don't know if you have something to say, but aren't saying it or if you simply don't understand what is being discussed. I suspect the former.

--

Rick C.

+++ Get 1,000 miles of free Supercharging
+++ Tesla referral code - https://ts.la/richard11209

dxforth

unread,
Jan 21, 2021, 6:58:12 PM1/21/21
to
Knowing when something is superfluous - that's style :)

none albert

unread,
Jan 22, 2021, 6:20:02 AM1/22/21
to
In article <1ac6bc84-490c-4a0b...@googlegroups.com>,
Rick C <gnuarm.del...@gmail.com> wrote:

Famous last words:
>The code in question, ... is simple enough to understand how it works
>and what it will do that I don't need to test it.

<SNIP>

>Rick C.

NN

unread,
Jan 22, 2021, 6:27:25 AM1/22/21
to
Since you asked so nicely....


In an earlier post you said that the function caused an ambigious condition. Which is why I asked you the question if you could give me an example.

The function is obvious ( even explicit ) in what it does. You give it the correct input or it aborts. There is nothing ambigious about that.

You and I seem to have different understanding of what an ambigious condition is.

I then asked, if you had tried running it in a forth? The function documents in a terse manner the inputs and outputs. Had you tried running it it would have become abundantly clear why suggesting 99 as an input was just silly.

You didnt read dxforth's reply either where he says that the calling routing will never send more than a nibble. Had you understood that, you would never have suggested 99 as an input.

Last, but not least you also said :

" the way this routine is written anything outside the range of 0-15 will cause an access outside the declared array"
" The code in question, + c@ is simple enough to understand"

In both instances you were wrong. You ignored the guards that stopped out of range accesses.


In your own words : " The code in question .... is simple enough to understand how it works and what it will do that I don't need to test it. " sums it up rather nicely.

The bottom line is you have demonstrated in spades that you did not understand what this kindergarten-level function did.

Rick C

unread,
Jan 22, 2021, 12:52:43 PM1/22/21
to
I am aware of the guards, I WAS ignoring them because I thought that was what we were talking about, the need for the guards. So I was discussing the code without the guards.

You were being rather silly trying to be coy asking questions rather than discussing the issue. If you had simply made your point we would have seen that we were both making the SAME point - that the guards are useful. But you wanted to play games instead.

--

Rick C.

---- Get 1,000 miles of free Supercharging
---- Tesla referral code - https://ts.la/richard11209

Kerr-Mudd,John

unread,
Jan 23, 2021, 4:32:17 AM1/23/21
to
No checks; permits lowercase hex chars; small, not fast:

hex2bin: ; 3x 41 61
and al,0x4F ; x 41 41
aam 0x37 ; 0/x 1/0A 1/0A


--
Bah, and indeed, Humbug.

Rick C

unread,
Jan 23, 2021, 4:47:51 AM1/23/21
to
Care to share which processor that runs on? I assume that is assembly language? I don't really recognize it. I guess that is Forth assembly?

I think in the Forth world the assembly language addicts tend toward the Intel processors, but they are not the majority of computing platforms these days. I'm pretty sure the mobile market is the single largest sink of processors running an OS. Toasters with Linux don't count.

--

Rick C.

---+ Get 1,000 miles of free Supercharging
---+ Tesla referral code - https://ts.la/richard11209

dxforth

unread,
Jan 23, 2021, 9:10:41 PM1/23/21
to
Interesting technique - not least because AAM takes an argument. Appears
to have been a hidden 'feature'.

A routine with checking I've used is:

\ Convert ascii character to binary
: >NIBBLE ( char -- nibble )
dup [char] 0 < ?badhex
dup [char] 9 > if
dup [char] A < ?badhex
dup [char] F > ?badhex 7 -
then 15 and ;

Perhaps someone has a better way?


Rick C

unread,
Jan 23, 2021, 9:42:58 PM1/23/21
to
Yes, I have a way I know is better. It will run on any Forth system rather than only ones running a specific processor.

: dh. ( d - )
base @ -rot #16 base !
<# 0 begin -rot # 2dup D0= 0= while
rot 1+ dup 4 mod 0= if '_' hold then repeat
drop s" 0x" holds #>
type base ! ;

The new google groups tosses formatting spaces, so sorry for the lack of formatting.

--

Rick C.

--+- Get 1,000 miles of free Supercharging
--+- Tesla referral code - https://ts.la/richard11209

Paul Rubin

unread,
Jan 23, 2021, 9:52:38 PM1/23/21
to
dxforth <dxf...@gmail.com> writes:
> \ Convert ascii character to binary
> : >NIBBLE ( char -- nibble )
> dup [char] 0 < ?badhex
> dup [char] 9 > if
> dup [char] A < ?badhex
> dup [char] F > ?badhex 7 -
> then 15 and ;
>
> Perhaps someone has a better way?

I guess it's a matter of taste:

\ Convert ascii character to binary
: >NIBBLE ( char -- nibble )
dup 'A' >= if 7 - then 48 -
dup -16 and if ?badhex then ;

Rick C

unread,
Jan 23, 2021, 10:21:20 PM1/23/21
to
dup 'A' >= 7 and - 48 -
dup -16 and if ?badhex then ;

Is there a situation where a conditional jump is preferred to a simple logic operation?

--

Rick C.

--++ Get 1,000 miles of free Supercharging
--++ Tesla referral code - https://ts.la/richard11209

Paul Rubin

unread,
Jan 23, 2021, 11:11:45 PM1/23/21
to
Rick C <gnuarm.del...@gmail.com> writes:
> dup 'A' >= 7 and - 48 -

Nice!

dxforth

unread,
Jan 24, 2021, 12:02:47 AM1/24/21
to
On 24/01/2021 14:21, Rick C wrote:
> On Saturday, January 23, 2021 at 9:52:38 PM UTC-5, Paul Rubin wrote:
>> dxforth <dxf...@gmail.com> writes:
>> > \ Convert ascii character to binary
>> > : >NIBBLE ( char -- nibble )
>> > dup [char] 0 < ?badhex
>> > dup [char] 9 > if
>> > dup [char] A < ?badhex
>> > dup [char] F > ?badhex 7 -
>> > then 15 and ;
>> >
>> > Perhaps someone has a better way?
>> I guess it's a matter of taste:
>> \ Convert ascii character to binary
>> : >NIBBLE ( char -- nibble )
>> dup 'A' >= if 7 - then 48 -
>> dup -16 and if ?badhex then ;
>
> \ Convert ascii character to binary
> : >NIBBLE ( char -- nibble )
> dup 'A' >= 7 and - 48 -
> dup -16 and if ?badhex then ;

Nice on those! (btw IF THEN can/should be removed)

>
> Is there a situation where a conditional jump is preferred to a simple logic operation?
>

When it involves several tests and you want to exit at the first failure.

dxforth

unread,
Jan 24, 2021, 12:38:12 AM1/24/21
to
Almost. Neither version excludes char 58..63

Rick C

unread,
Jan 24, 2021, 1:47:04 AM1/24/21
to
Yes, knowing when something is superfluous - that's style :)

--

Rick C.

-+-- Get 1,000 miles of free Supercharging
-+-- Tesla referral code - https://ts.la/richard11209

none albert

unread,
Jan 24, 2021, 8:28:17 AM1/24/21
to
Only very few of the primitives need to be really fast.
One of these is ( char string -- ) find character in string.
Then profit by using it!

This one returns a digit and a flag, handles lower and upper
case.
( char base -- digit flag )
: DIGIT SWAP 0x20 OR
"0123456789abcdefghijklmnopqrstuvwxyz" OVER >R ROT $^ R> -
SWAP OVER U> ;

Note that there are no paths. A single test suffices.
REGRESS &z 10 DIGIT NIP &z 100 DIGIT S: 0 35 -1

Groetjes Albert

Kerr-Mudd,John

unread,
Jan 24, 2021, 4:59:42 PM1/24/21
to
On Sat, 23 Jan 2021 09:47:50 GMT, Rick C
<gnuarm.del...@gmail.com> wrote:

> On Saturday, January 23, 2021 at 4:32:17 AM UTC-5, Kerr-Mudd,John
> wrote:

[Hex 2 binary]

>> >
>> No checks; permits lowercase hex chars; small, not fast:
>>
>> hex2bin: ; 3x 41 61
>> and al,0x4F ; x 41 41
>> aam 0x37 ; 0/x 1/0A 1/0A
>
> Care to share which processor that runs on? I assume that is assembly
> language? I don't really recognize it. I guess that is Forth
> assembly?

no, nasm x86.

yes, procesoor specific.

Rick C

unread,
Jan 24, 2021, 8:14:11 PM1/24/21
to
Yes, I should have realized it's not a Forth assembly since the opcode is in the front. I do not recognize the syntax. I guess things have changed from 8080 days.

--

Rick C.

-+-+ Get 1,000 miles of free Supercharging
-+-+ Tesla referral code - https://ts.la/richard11209

dxforth

unread,
Jan 24, 2021, 8:52:23 PM1/24/21
to
On 25/01/2021 00:28, albert wrote:
> In article <ruj142$1b8n$1...@gioia.aioe.org>, dxforth <dxf...@gmail.com> wrote:
>>On 24/01/2021 15:11, Paul Rubin wrote:
>>> Rick C <gnuarm.del...@gmail.com> writes:
>>>> dup 'A' >= 7 and - 48 -
>>>
>>> Nice!
>>>
>>
>>Almost. Neither version excludes char 58..63
>
> Only very few of the primitives need to be really fast.
> One of these is ( char string -- ) find character in string.
> Then profit by using it!
>
> This one returns a digit and a flag, handles lower and upper
> case.
> ( char base -- digit flag )
> : DIGIT SWAP 0x20 OR
> "0123456789abcdefghijklmnopqrstuvwxyz" OVER >R ROT $^ R> -
> SWAP OVER U> ;
>
> Note that there are no paths. A single test suffices.
> REGRESS &z 10 DIGIT NIP &z 100 DIGIT S: 0 35 -1

Perhaps the simplest approach so far. Most forths would have SCAN
as a primitive.

dxforth

unread,
Jan 24, 2021, 9:01:54 PM1/24/21
to
On 24/01/2021 17:47, Rick C wrote:
> On Sunday, January 24, 2021 at 12:38:12 AM UTC-5, dxforth wrote:
>> On 24/01/2021 15:11, Paul Rubin wrote:
>> > Rick C <gnuarm.del...@gmail.com> writes:
>> >> dup 'A' >= 7 and - 48 -
>> >
>> > Nice!
>> >
>> Almost. Neither version excludes char 58..63
>
> Yes, knowing when something is superfluous - that's style :)
>

Yes. While inputs can be uncertain, outputs rarely are.

Rick C

unread,
Jan 25, 2021, 12:05:19 AM1/25/21
to
On Sunday, January 24, 2021 at 8:28:17 AM UTC-5, none albert wrote:
> In article <ruj142$1b8n$1...@gioia.aioe.org>, dxforth <dxf...@gmail.com> wrote:
> >On 24/01/2021 15:11, Paul Rubin wrote:
> >> Rick C <gnuarm.del...@gmail.com> writes:
> >>> dup 'A' >= 7 and - 48 -
> >>
> >> Nice!
> >>
> >
> >Almost. Neither version excludes char 58..63
> Only very few of the primitives need to be really fast.
> One of these is ( char string -- ) find character in string.
> Then profit by using it!
>
> This one returns a digit and a flag, handles lower and upper
> case.
> ( char base -- digit flag )
> : DIGIT SWAP 0x20 OR
> "0123456789abcdefghijklmnopqrstuvwxyz" OVER >R ROT $^ R> -
> SWAP OVER U> ;
>
> Note that there are no paths. A single test suffices.
> REGRESS &z 10 DIGIT NIP &z 100 DIGIT S: 0 35 -1

So what is $^ ? I can't find that. Specific to your Forth?

--

Rick C.

-++- Get 1,000 miles of free Supercharging
-++- Tesla referral code - https://ts.la/richard11209

Coos Haak

unread,
Jan 25, 2021, 8:39:48 AM1/25/21
to
Op Sun, 24 Jan 2021 17:14:09 -0800 (PST) schreef Rick C:

> On Sunday, January 24, 2021 at 4:59:42 PM UTC-5, Kerr-Mudd,John wrote:
>> On Sat, 23 Jan 2021 09:47:50 GMT, Rick C
>> <gnuarm.del...@gmail.com> wrote:
>>
>>> On Saturday, January 23, 2021 at 4:32:17 AM UTC-5, Kerr-Mudd,John
>>> wrote:
>> [Hex 2 binary]
>>>> >
>>>> No checks; permits lowercase hex chars; small, not fast:
>>>>
>>>> hex2bin: ; 3x 41 61
>>>> and al,0x4F ; x 41 41
>>>> aam 0x37 ; 0/x 1/0A 1/0A
>>>
>>> Care to share which processor that runs on? I assume that is assembly
>>> language? I don't really recognize it. I guess that is Forth
>>> assembly?
>> no, nasm x86.
>>
>> yes, procesoor specific.
>
> Yes, I should have realized it's not a Forth assembly since the opcode is in the front. I do not recognize the syntax. I guess things have changed from 8080 days.

I know of quite a few Forth assemblers that have the opcode in front.
E.g. ciforth, chforth, FPC, Win32Forth and more.

groet Coos

Alexander Wegel

unread,
Jan 25, 2021, 8:48:41 AM1/25/21
to
albert <albert@cherry.(none)> wrote:

> In article <ruj142$1b8n$1...@gioia.aioe.org>, dxforth <dxf...@gmail.com> wrote:
> >On 24/01/2021 15:11, Paul Rubin wrote:
> >> Rick C <gnuarm.del...@gmail.com> writes:
> >>> dup 'A' >= 7 and - 48 -
> >>
> >> Nice!
> >>
> >
> >Almost. Neither version excludes char 58..63
>
> Only very few of the primitives need to be really fast.
> One of these is ( char string -- ) find character in string.
> Then profit by using it!
>
> This one returns a digit and a flag, handles lower and upper
> case.
> ( char base -- digit flag )
> : DIGIT SWAP 0x20 OR
> "0123456789abcdefghijklmnopqrstuvwxyz" OVER >R ROT $^ R> -
> SWAP OVER U> ;
>
> Note that there are no paths. A single test suffices.
> REGRESS &z 10 DIGIT NIP &z 100 DIGIT S: 0 35 -1
>
> Groetjes Albert

Scan for the char, really??

Unless $^ is O(1), this should perform rather poor & with a quite some
variation in timing!

How about the other way round? E.g.:

hex
create digs \ character -> digit value lookup table
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c, \ [$00]
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c,
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c, \ [$10]
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c,
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c, \ [$20]
ff c, ff c, ff c, ff c, ff c, ff c, ff c, ff c,
0 c, 1 c, 2 c, 3 c, 4 c, 5 c, 6 c, 7 c, \ [$30]
8 c, 9 c, ff c, ff c, ff c, ff c, ff c, ff c,
ff c, a c, b c, c c, d c, e c, f c, 10 c, \ [$40]
11 c, 12 c, 13 c, 14 c, 15 c, 16 c, 17 c, 18 c,
19 c, 1a c, 1b c, 1c c, 1d c, 1e c, 1f c, 20 c, \ [$50]
21 c, 22 c, 23 c, ff c, ff c, ff c, ff c, ff c,
ff c, a c, b c, c c, d c, e c, f c, 10 c, \ [$60]
11 c, 12 c, 13 c, 14 c, 15 c, 16 c, 17 c, 18 c,
19 c, 1a c, 1b c, 1c c, 1d c, 1e c, 1f c, 20 c, \ [$70]
21 c, 22 c, 23 c, ff c, ff c, ff c, ff c, ff c,

: >dig ( char--digit|$ff) chars digs + c@ ;
: DIGIT ( char base -- digit flag ) >r >dig dup r> < ;

Stephen Pelc

unread,
Jan 25, 2021, 9:03:32 AM1/25/21
to
On Sun, 24 Jan 2021 17:14:09 -0800 (PST), Rick C
<gnuarm.del...@gmail.com> wrote:

>> >> hex2bin: ; 3x 41 61
>> >> and al,0x4F ; x 41 41
>> >> aam 0x37 ; 0/x 1/0A 1/0A
>> >
>> > Care to share which processor that runs on? I assume that is assembly
>> > language? I don't really recognize it. I guess that is Forth
>> > assembly?
>> no, nasm x86.
>>
>> yes, procesoor specific.
>
>Yes, I should have realized it's not a Forth assembly since the opcode is
> in the front. I do not recognize the syntax. I guess things have changed
> from 8080 days.

They have changed a lot. Our assemblers have the opcide in front as
well.

Stephen


--
Stephen Pelc, ste...@vfxforth.com <<< NEW
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, +44 (0)78 0390 3612
web: http://www.mpeforth.com - free VFX Forth downloads

Hugh Aguilar

unread,
Jan 25, 2021, 1:51:08 PM1/25/21
to
> On Tuesday, May 26, 2015 at 11:37:37 AM UTC-7, Elizabeth D. Rather wrote:
> > On 5/26/15 8:15 AM, rickman wrote:
> > > On 5/26/2015 1:20 PM, WJ wrote:
> > >> That code is unreadable and unmaintainable. It's very hard
> > >> to figure out how it accomplishes its task. I would not
> > >> pay a programmer to produce code like that.
> > >>
> > >> This is somewhat more understandable:
> > >>
> > >> : >char
> > >> dup 9 > if [char] A 10 - else [char] 0 then
> > >> + ;
> > >
> > > If you have any reason to look at the definition of >char then I can't
> > > see how you would not understand how it works. Perhaps this would be a
> > > better definition...
> > >
> > > \ Convert n to ASCII char
> > > : >CHAR ( n -- char ) DUP 9 > 7 AND + ASCII 0 + ;
> > >
> > > Lol, saying it is unreadable and unmaintainable is a bit of a stretch. I
> > > think that exact code has been read and understood as well as maintained
> > > for many years now. I am pretty sure I have seen something similar to
> > > it way back when I was learning assembly language. I think it took me
> > > two minutes to see what it was doing.
> >
> > Indeed, proper documentation as in rickman's version above is essential
> > to readable & maintainable code. Neither of the previous versions is
> > acceptable, although I find the shorter code quite clear (and, as
> > rickman notes, it's been around for many years). I would have preferred
> > [CHAR] instead of ASCII, however, as it's Standard.
> >
> > Cheers,
> > Elizabeth

This is a big part of why I don't have respect for maintenance programmers.
They get stuck with crap code such as shown above, and they aren't allowed
to rewrite it, so they just have to accept it.
If they complain that it is crap code, an elitist clown will tell bully them into submission:

> Honestly, this is only a problem if you don't know that idiom. A lot of
> people don't know that you can use masks and logical operations, so they
> will find that operation strange.
> ...
> Therefore, I would reiterate what I told Hugh some times: If you don't know
> something, it's *not* the fault of the person who uses and knows that thing.
> It's entirely your fault, and if you want to be a wise person, you'd rather
> learn it than complain.

Bullying is the lifeblood of elitist clowns --- they need maintenance programmers
to brown-nose them --- they can't be elite without this brown-nosing.
Bernd Paysan and Elizabeth Rather are incompetent. Their code is crap.
They rely entirely on bullying to be elite --- bullying is their only skill.

dxforth

unread,
Jan 25, 2021, 6:10:53 PM1/25/21
to
Reviewing my original code it seems there was a 'method to the madness'.
Conversion is performed only after excluding illegal values. It was
logically easier than keeping a copy of the character, converting it
and sorting out the mess at the end. If it wasn't for the error routine
needing to display the offending character, the latter method would
have sufficed.

Paul Rubin

unread,
Jan 25, 2021, 6:36:28 PM1/25/21
to
ste...@mpeforth.com (Stephen Pelc) writes:
> Our assemblers have the opcide in front as well.

Do the opcode words parse the parameters? Or do they push stuff that
the parameters then comma in? I remember thinking the old style
assemblers were fiendishly clever even though they turned stuff around
backwards.

dxforth

unread,
Jan 25, 2021, 6:39:24 PM1/25/21
to
On 26/01/2021 05:51, Hugh Aguilar wrote:
>
> Bullying is the lifeblood of elitist clowns --- they need maintenance programmers
> to brown-nose them --- they can't be elite without this brown-nosing. [...]
> They rely entirely on bullying to be elite --- bullying is their only skill.
>

It's the nature of community to want a leader who can bully. The world didn't
wake up one day to IEEE-754 and say 'What a great idea - I'll implement that'.
They were courted and cajoled, and if that didn't work, ultimately bullied
into it by public pressure. The same goes for any Standard you can name or
invent. Isn't it great Forth was created by someone who cared nothing for
leadership or for followers? If 'no' then you need someone who can bully.

dxforth

unread,
Jan 25, 2021, 6:48:08 PM1/25/21
to
Check out PASM.SEQ in Zimmer's F-PC. It was one of the first PD
systems to use it. In fact you could switch between modes using
PREFIX and POSTFIX.

Paul Rubin

unread,
Jan 25, 2021, 10:49:19 PM1/25/21
to
dxforth <dxf...@gmail.com> writes:
> It's the nature of community to want a leader who can bully. The
> world didn't wake up one day to IEEE-754 and say 'What a great idea -
> I'll implement that'. They were courted and cajoled, and if that
> didn't work, ultimately bullied into it by public pressure.

Prof. Kahan tells it differently:

It was remarkable that so many hardware people there, knowing how
difficult p754 would be, agreed that it should benefit the community at
large. If it encouraged the production of floating-point software and
eased the development of reliable software, it would help create a
larger market for everyone's hardware. This degree of altruism was so
astonishing that MATLAB's creator Dr. Cleve Moler used to advise foreign
visitors not to miss the country's two most awesome spectacles: the
Grand Canyon, and meetings of IEEE p754."

( https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html )

Paul Rubin

unread,
Jan 25, 2021, 10:52:11 PM1/25/21
to
dxforth <dxf...@gmail.com> writes:
> Almost. Neither version excludes char 58..63

Arggh. Can be fixed by adding some hair though. In the same
Lovecraftian spirit:

: ir ( a -- n )
dup dup '9' > 100 and + swap 'A' >= 107 and - 48 - ;
: >nibble ( char -- nibble ) ir dup -16 and if ?badhex then ;

Andy Valencia

unread,
Jan 26, 2021, 12:16:53 AM1/26/21
to
Paul Rubin <no.e...@nospam.invalid> writes:
> I remember thinking the old style
> assemblers were fiendishly clever even though they turned stuff around
> backwards.

I don't feel like it was any more "backwards" than expressions
with RPN in general. In Forth in general the mindset is to push
the arguments, then "fire" the operator. It became quickly natural
to think about the opcodes the same way.

(The compactness and feature set of such assembler impresses me, too.)

Andy Valencia
Home page: https://www.vsta.org/andy/
To contact me: https://www.vsta.org/contact/andy.html

Paul Rubin

unread,
Jan 26, 2021, 4:14:46 AM1/26/21
to
dxforth <dxf...@gmail.com> writes:
> Check out PASM.SEQ in Zimmer's F-PC. It was one of the first PD
> systems to use it. In fact you could switch between modes using
> PREFIX and POSTFIX.

I'll try to take a look sometime, but any idea how prefix mode worked?
In postfix mode, if you said "AX DX MOV", AX and DX would each push some
bits into stack cells, and then MOV would use the two cells to assemble
an instruction and comma it. But in prefix mode, I can see
a few ways for "MOV AX DX" to work and none are pretty. If MOV has to
parse (and similarly ADD, SUB, and so on) then things get somewhat
messy handling register names, address modes, etc.

Alternatively MOV could leave some kind of marker on the stack that AX
would find to discover that it was the 1st operand of a 2-operand
instruction, etc. That gets messy too.

Maybe there's some other approach that I'm missing.

Kerr-Mudd,John

unread,
Jan 26, 2021, 4:24:16 AM1/26/21
to
On Mon, 25 Jan 2021 18:51:06 GMT, Hugh Aguilar <hughag...@gmail.com>
wrote:

>> On Tuesday, May 26, 2015 at 11:37:37 AM UTC-7, Elizabeth D. Rather
>> wrote:
[]

>> > Cheers,
>> > Elizabeth
>
[]
> Bullying is the lifeblood of elitist clowns --- they need maintenance
> programmers to brown-nose them --- they can't be elite without this
> brown-nosing. Bernd Paysan and Elizabeth Rather are incompetent. Their
> code is crap. They rely entirely on bullying to be elite --- bullying
> is their only skill.
>
>
You seem very bitter, digging up a supposed snub from 2015.
You're hardly likely to accepted by the elite with these insults.

Anton Ertl

unread,
Jan 26, 2021, 5:00:34 AM1/26/21
to
Paul Rubin <no.e...@nospam.invalid> writes:
>I'll try to take a look sometime, but any idea how prefix mode worked?

It stores the instruction somewhere, and the next instruction word (or
END-CODE) actually EXECUTEs it. At least that's the general principle
of prefix modes, details may vary.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2020: https://euro.theforth.net/2020

Rick C

unread,
Jan 26, 2021, 5:25:00 AM1/26/21
to
You must be new here. Either that or you have a perverse sense of humor.

I too, reject acceptance by the elite of Forth even if I were to somehow attain it.

--

Rick C.

-+++ Get 1,000 miles of free Supercharging
-+++ Tesla referral code - https://ts.la/richard11209

Rick C

unread,
Jan 26, 2021, 5:28:44 AM1/26/21
to
On Tuesday, January 26, 2021 at 5:00:34 AM UTC-5, Anton Ertl wrote:
> Paul Rubin <no.e...@nospam.invalid> writes:
> >I'll try to take a look sometime, but any idea how prefix mode worked?
> It stores the instruction somewhere, and the next instruction word (or
> END-CODE) actually EXECUTEs it. At least that's the general principle
> of prefix modes, details may vary.

I get that. There's nothing about Forth that forces postfix notation. But what's with the slashes?

hex2bin: ; 3x 41 61
and al,0x4F ; x 41 41
aam 0x37 ; 0/x 1/0A 1/0A

I also don't get the semi colons, but I realize they are at least Forth.

--

Rick C.

+--- Get 1,000 miles of free Supercharging
+--- Tesla referral code - https://ts.la/richard11209

P Falth

unread,
Jan 26, 2021, 6:25:50 AM1/26/21
to
On Tuesday, 26 January 2021 at 11:28:44 UTC+1, gnuarm.del...@gmail.com wrote:
> On Tuesday, January 26, 2021 at 5:00:34 AM UTC-5, Anton Ertl wrote:
> > Paul Rubin <no.e...@nospam.invalid> writes:
> > >I'll try to take a look sometime, but any idea how prefix mode worked?
> > It stores the instruction somewhere, and the next instruction word (or
> > END-CODE) actually EXECUTEs it. At least that's the general principle
> > of prefix modes, details may vary.
> I get that. There's nothing about Forth that forces postfix notation. But what's with the slashes?
> hex2bin: ; 3x 41 61
> and al,0x4F ; x 41 41
> aam 0x37 ; 0/x 1/0A 1/0A
> I also don't get the semi colons, but I realize they are at least Forth.
>
It was said above that this is Nasm source. The ; start a comment in that case.
It is a nice and compact function. Unfortunatly AAM is not supported in 64 bit mode.
Translated to Forth the function becomes

: HEX2BIN ( c -- n ) $4F AND $37 MOD ;

$4F AND does 2 things.
1. Translates a..f to uppercase
2. If c is '0'..'9' that is $30..$39 it removes $30 and leaves 0..9

$37 MOD translates 'A'..'F' to 10..15.
'A' = 65, $37 = 55
65 55 mod = 10

Peter
It is loading more messages.
0 new messages