Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More byte squeezing #10

Open
thamesynne opened this issue Nov 7, 2023 · 4 comments
Open

More byte squeezing #10

thamesynne opened this issue Nov 7, 2023 · 4 comments

Comments

@thamesynne
Copy link

thamesynne commented Nov 7, 2023

Another 4 bytes can be saved in find:

    mov bx,[LATEST]
.1: test bx,bx
    jz error

    mov si,bx
    lodsw
    xchg ax,bx        ; insert this here
    lodsb
    mov dl,al
    and al,LEN_MASK
    cmp al,cl
    jne .1            ; change from jne .2

    push cx
    push di
    repe cmpsb
    pop di
    pop cx

    jne .1            ; change from jne .3
; .2:  mov bx,[bx]   --- delete this 
;      jmp .1
.3:   xchg ax,si   ; change from mov ax,si - si is immediately overwritten
@thamesynne
Copy link
Author

thamesynne commented Nov 7, 2023

Also, error: could use mov al,13 instead of mov ax,13 for an extra byte.

@thamesynne
Copy link
Author

thamesynne commented Nov 7, 2023

And since >IN depends on TIB being 0, using xor di,di instead of mov di, TIB saves another byte. (Likewise cmp di,TIB could become test di,di in the backspace routine, but that's outside the bytecount).

@garysnyder
Copy link

If you want so squeeze more consider :
name of primitive sp@ could be S
then in hello_world.forth use : sp@ s ;
(two bytes in the primitive Dictionary saved.
nand can be n with : nand n ;
Three more bytes
Something similar can be done for RP@, but it is a little trickier.

: TIB 0 ;
: TIBP1 1 ;
: 0x1000 1 2* 2* 2* 2* 2* 2* 2* 2* 2* 2* 2* 2* ;
: STATE 0x1000 ;
: >IN 0x1000 2 + ;
: LATEST 0x1000 2 2 + + ;
: HERE 0x1000 6 + :
That should eliminate the s@ primitive, cutting another 5 bytes or so ...

I could be wrong but that looks like 10 bytes cut out of the BIN file.

We can remove 0= or 0# or whatever with the swapbyte and leftshift / leftsmear
concept I said over in sectorforth. I think that is another 8 or 9 bytes.

key and emit need to go, but that will probably not save any space.
Milli/Secotr forth need to be able to call a sw int to have access to the
com ports, floppy disk, etc. If the language is going to start self modifying
it's primitive machine code, that seems out of bounds.

-Gar.

@garysnyder
Copy link

Here is the 0= , lshift, rshift, rrot and lrot <, > etc.
I take no responsibility for yupos.

: lshift dup + ;
: lshift3 lshift lshift lshift ;
: lshift4 lshift3 lshift ;
lshift15 lshift4 lshift4 lshift4 lshift3 ;

: lsmear dup lshift or ;
: lsmear4 lsmear lsmear lsmear lsmear ;
: lsmear16 lsmear4 lsmear4 lsmear4 lsmear4 ;

; drop2under swap drop swap drop ;

: swapbyte dup sp@ 1 + @ drop2under ; (this is the equivalent of rotate right 8 bits )

: <>0 lsmear16 swapbyte lshift swapbyte lsmear16 ;
: =0 <>0 not ;

: 2* dup + ;
: 16* 2* 2* 2* 2* ;
: 8 1 2* 2* 2* ;
: 0x8000 8 16* 16* 16* ;
: <0 0x8000 and <>0 ;
: >=0 <0 not ;
: >0 dup <>0 swap >=0 and ;
: <=0 >0 not ;
: < - <0 ;
: <= - <=0 ;
: > - >0 ;
: >= sub >=0 ;
: <> - <>0 ;
: = =0 ;

: bit0to15 lshift15 ;
: bit15to0 swapbyte lshift swapbyte 1 and ;
: lrot dup lshift swap bit15to0 or ;

: rshifthigh swapbyte 255 and lshift7 :
: rshiftlow lshift7 swapbyte 127 and ;
: rshift dup rshiftlow swap rshifthigh or ;

: rrot dup rshift swap bit0to15 or ;

There is probably errors in there, but you get the idea.
-GAr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants