P.S. I forgot to put in `18 TS$=TIME$`, so the timing is inaccurate. Once I got that corrected it does seem like PEEKing at the bytes in the integer is faster than dividing by 4096.
On Thu, Oct 27, 2022 at 8:38 PM B 9 <[email protected]> wrote: > On Thu, Oct 27, 2022 at 3:04 PM John R. Hogerhuis <[email protected]> > wrote: > >> >> With hex it's a question though since MOD 16 can be done with AND 15 >> which is probably faster than a general integer 16 modulus. There's no >> bitshift operator so you still need a integer divide by 16%. Who knows how >> efficient an integer divide by 16 is in the interpreter versus 4096 >> (integer) divides. >> > > That's a good question about efficiency. Integer division by 4096 seems > reasonably quick, but it would have been nice if BASIC had exposed the bit > shift operators. (I'm presuming the 8085 had some, right?) > > I'm not sure it'd be any faster than division by 4096, but one could use > the fact that we're using a 2-byte integer for the address and just look at > each byte. > hexit.do > > 1 TS$=TIME$ > 5 DIM H$(15): *FOR* T=0 *TO* 9:H$(T)=CHR$(48+T): *NEXT* T: *FOR* T=ASC("A") > *TO* ASC("F"): H$(T-55)=CHR$(T): *NEXT* > 6 DIM R$(7): *FOR* T=0 *TO* 7: R$(T)=" ": *NEXT* > 10 DEFINT A-F, P: D=0: P=VARPTR(D) > 15 INPUT "Start"; ST% > 16 INPUT "End"; EN% > 20 *FOR* D=ST% *TO* EN% > 30 *IF* (D MOD 8) = 0 *THEN* *PRINT*" ";: *FOR* T=0 *TO* 7: *PRINT* R$(T);: > *NEXT*: *PRINT*: S=0: *GOSUB* 400 > 40 *GOSUB* 200 > 90 *NEXT* > 100 REM Timing > 110 TE$=TIME$ > 115 *PRINT* > 120 *PRINT* TS$ " to " TE$ > 199 *END* > 200 REM Print 2 hexits > 201 *' *Input: D is address of an 8-bit integer202* '* Output: None, but 2 > hexits are printed followed by a space > 210 A=PEEK(D) > 220 *PRINT *H$(A\16); H$(A MOD 16); " "; > 230 *IF* A<32 *THEN* A=46 > 240 R$(S)=CHR$(A) > 250 S=S+1 > 260 *RETURN* > 400 REM Print 4 hexits > 401 *' *Input: P is address of a 16-bit little endian integer > 402* '* Output: None, but 4 hexits are printed followed by a space > 410 A=PEEK(P+1): B=PEEK(P) > 420 *PRINT *H$(A\16); H$(A MOD 16); H$(B\16); H$(B MOD 16); " "; > 430 *RETURN* > > ------------------------------ > —b9 >
