I was curious if loading a string pointer could be done without an explicit
IF.

Seems like what we're doing is J as LSB, K as MSB

K>127: J + K*256-65536
or
K<=127: J + K*256 - 0

Taking J + K * 256 - 65536

factoring out 256 and putting both functions in a similar form:

K > 127: J + 256 ( K - 256)
K <= 127: J + 256 ( K - 0 )

Knowing comparisons can be done without 'IF'... if an expression is true
you get -1 and 0 if false, we can inline the conditional into the
expression

So the computation without IF would be

J + 256% * ( K + 256% * (K > 127%))

So something like this:

10 DEFINTP:DEFSTRH
20 H=CHR$(201)
30 P=VARPTR(H)+1
1000 P=PEEK(P)+256%*(PEEK(P+1)+256%*(PEEK(P+1)>127))
1010 PRINTP

Not sure if this works, particularly with the integer constants. And there
might be speed optimizations... certainly it is doing the MSB peek twice.

-- John.

Reply via email to