CRC-32 native code for DOS GForth 0.5.0 
Author Message
 CRC-32 native code for DOS GForth 0.5.0

\ Hi
\ At last I managed to write for GForth. But only for DOS.
\ I get part of the code from SEEing DROP and DUP
\ I am sorry if the postings disturb you all, I hope these small programs
can serve as demos
\ or comparisons. If these programs can be used as samples, feel free to
include them
\ in the Forth package.

\ crc-32.fs for GForth
\ Petrus Prawirodidjojo 2001-10-21

code crc32  ( n1 char -- n2 )
    4 # si add   \ pop crc to edx
    si ) dx mov
    8 # cx mov   \ loop count
begin
    1 # dx shr   \ shift crc
    1 # bh rcr
    1 # bl ror   \ shift character
    .w bx ax mov  \ save character
    bh bl xor   \ xor
0< if    \ skip if equal
    $EDB88320 # dx xor  \ crc-32 polymial 1 04C1 1DB7
     then
    .w ax bx mov  \ restore character
  loop    \ next bit
    dx bx mov   \ crc to tos
    $2CED8 #) ax mov  \ system dependent, see 'drop'
    ax ) cx mov   \ system dependent
    4 # $2CED8 #) add  \ system dependent
    cx ) jmp   \ system dependent
    end-code

\ calculate crc-32 for several strings
: crc-32  ( n1 c-addr u -- n2 )
    0 do   \ n c-addr

\ calculate crc-32 of a string
: crc32s  ( c-addr u -- n )
    -1 rot rot crc-32 invert ;

\ test
: test
    cr cr ." crc-32" cr
    s" An Arbitrary String" 2dup type cr
    ."   crc-32: " crc32s hex u. decimal ." should be 6FBEAAE7" cr
    s" ZYXWVUTSRQPONMLKJIHGFEDBCA" 2dup type cr
    ."   crc-32: " crc32s hex u. decimal ." should be 99CDFDB2" cr ;

test

cr unused u. .( bytes free. )
key bye
\ end of application, - do not delete -



Thu, 08 Apr 2004 21:14:32 GMT  
 CRC-32 native code for DOS GForth 0.5.0

Impossible to believe that Gforth dumped the nice McKewan assembler when going
from 0.49 to 0.50!

This is tested and works ( NT 4.0 in a DOS window ) for
  GForth 0.4.9, Copyright (C) 1998 Free Software Foundation, Inc.

I used gforth-f.exe .

-marcel

\ crc-32.fs for GForth
\ Petrus Prawirodidjojo 2001-10-21

ALSO ASSEMBLER DEFINITIONS
        : NEXT,
        ( mov     eax , 0 [ebp] ) $8B C, $45 C, $0 C,
        ( add     ebp , # 4     ) $83 C, $C5 C, $4 C,
        ( jmp     [eax]         ) $FF C, $20 C, ;
PREVIOUS DEFINITIONS

CODE crc32  ( n1 char -- n2 )
        4 # esi add,            \ pop crc to edx
        0 [esi] edx mov,
        8 # ecx mov,            \ loop count
BEGIN,  edx shr,                \ shift crc
        bh  rcr,
        bl  ror,                \ shift character
        ebx eax mov,            \ save character
        bh  bl  xor,
 0< IF,      $EDB88320 # edx xor,    \ crc-32 polymial 1 04C1 1DB7
  THEN, eax ebx mov,            \ restore character
LOOP,   edx ebx mov,            \ crc to tos
        NEXT,
END-CODE

\ calculate crc-32 for several strings
\ calculate crc-32 of a string

: crc32s  ( c-addr u -- n )     -1 -ROT crc-32 INVERT ;

: test  CR CR ." crc-32"
        CR S" An Arbitrary String" 2DUP TYPE
        CR ."   crc-32: " crc32s HEX U. DECIMAL ." should be 6FBEAAE7"
        CR S" ZYXWVUTSRQPONMLKJIHGFEDBCA" 2DUP TYPE
        CR ."   crc-32: " crc32s HEX U. DECIMAL ." should be 99CDFDB2" ;

0 [IF]
include crc32.fs  ok
see next,
: NEXT,
  139 C, 69 C, 0 C, 131 C, 197 C, 4 C, 255 C, 32 C, ; ok
see crc32
Code crc32
( $D1E70 )  add     esi , # 4  \ $81 $C6 $4 $0 $0 $0
( $D1E76 )  mov     edx , [esi]  \ $8B $16
( $D1E78 )  mov     ecx , # 8  \ $B9 $8 $0 $0 $0
( $D1E7D )  shr     edx , 1  \ $D1 $EA
( $D1E7F )  rcr     bh , 1  \ $D0 $DF
( $D1E81 )  ror     bl , 1  \ $D0 $CB
( $D1E83 )  mov     eax , ebx  \ $8B $C3
( $D1E85 )  xor     bl , bh  \ $32 $DF
( $D1E87 )  jns     D1E8F  \ $79 $6
( $D1E89 )  xor     edx , # EDB88320  \ $81 $F2 $20 $83 $B8 $ED
( $D1E8F )  mov     ebx , eax  \ $8B $D8
( $D1E91 )  loop    D1E7D  \ $E2 $EA
( $D1E93 )  mov     ebx , edx  \ $8B $DA
( $D1E95 )  mov     eax , 0 [ebp]  \ $8B $45 $0
( $D1E98 )  add     ebp , # 4  \ $83 $C5 $4
( $D1E9B )  jmp     [eax]  \ $FF $20
( $D1E9D )  and     [eax] , ah  \ $20 $20
( $D1E9F )  and     D [esi] [ebx] , bl  \ $20 $5C $1E $D
end-code
 ok
test

crc-32
An Arbitrary String
  crc-32: 6FBEAAE7 should be 6FBEAAE7
ZYXWVUTSRQPONMLKJIHGFEDBCA
  crc-32: 99CDFDB2 should be 99CDFDB2 ok

[THEN]



Fri, 09 Apr 2004 00:30:12 GMT  
 CRC-32 native code for DOS GForth 0.5.0
Marcel Hendrix schrieb:

Quote:


> Impossible to believe that Gforth dumped the nice McKewan assembler when going
> from 0.49 to 0.50!

We had to, since there were requests for adding all the stuff that Intel
and AMD introduced after the McKewan assembler was written. Instead of
adding all that stuff, we just added the bigFORTH assembler.

BTW: The easiest thing to implement NEXT is to jump to NOOP - that will
always work, regardless how NEXT is implemented in the version you are
using. Actually, there already *is* a NEXT in the assembler, it's
defined as

: next ['] noop >code-address rel) jmp ;

--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/



Fri, 09 Apr 2004 06:01:31 GMT  
 CRC-32 native code for DOS GForth 0.5.0


Quote:
>Marcel Hendrix schrieb:
>> Impossible to believe that Gforth dumped the nice McKewan assembler when going
>> from 0.49 to 0.50!

>We had to, since there were requests for adding all the stuff that Intel
>and AMD introduced after the McKewan assembler was written. Instead of
>adding all that stuff, we just added the bigFORTH assembler.

OTOH, maybe Marcel wants to volunteer to add this stuff to McKewan's
assembler, and write user documentation for it:-)

While I am at wishful thinking, a disassembler compatible with the
assembler would be nice, especially for the assembly coders (I am not
sure if I (a disassembler-only user) would prefer a disassembler that
outputs bigForth-assembler-style disassembly:-).

- 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



Wed, 14 Apr 2004 00:43:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CRC-32 native code for VFX Forth

2. CRC-32 native code for SwiftForth

3. CRC-32 native code for Win32Forth

4. Need PL1 CRC-16 or CRC-32 code

5. CRC-16, CRC-32 question/problem

6. CRC-16 and CRC-32 files wanted

7. 32 and/or 64 bit CRC code

8. 32 bit parallel CRC VHDL code

9. CRC-32 code wanted

10. 386 32 bit CRC code...

11. Help: CRC-32 encode/decode vhdl source code wanted

12. 32-bit DOS Code?

 

 
Powered by phpBB® Forum Software