Path: news.cs.au.dk!not-for-mail From: Morten Grouleff Newsgroups: comp.lang.beta Subject: Re: How to do low level stuff Date: 07 Jan 1999 16:23:49 +0100 Organization: Mjolner Informatics Lines: 96 Message-ID: References: <368B8A70.CF9934FF@thestar.ca> NNTP-Posting-Host: heimdal.mjolner.dk Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: xinwen.cs.au.dk 915722675 10288 255.255.255.255 (7 Jan 1999 15:24:35 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 7 Jan 1999 15:24:35 GMT To: Karl Waclawek X-Newsreader: Gnus v5.5/Emacs 19.34 Xref: news.cs.au.dk comp.lang.beta:11764 Karl Waclawek writes: > I knew about BETA for a while and recently I have spent > more time with the Personal Edition on Linux (since it is one > of the few visual development environments available there). > > I find it conceptually the most elegant language I have > ever seen, however, I have trouble to see how one would code > low level, "byte processing" functionality. > > For example: Here is a CRC routine I coded in Object Pascal (Delphi 4): [... example ...] > As one can see, there is bit-shifting involved as well as accessing > the low/high byte of a word and the low/high word of a longword. > > How would such a routine be coded in BETA? > Would it be efficient? > > Or would I have to resort to another language (like OP or C) > and call it from BETA? You could do it in C and call that from BETA. But you could also do it in BETA: ORIGIN '~beta/basiclib/betaenv'; --PROGRAM: descriptor-- (# BufType: (# R: [0]@Char #); CRCTable: [256]@Integer; InitCRCTable: (# do (* Initialize CRCTable here. Not included ;) *) #); GetCRC32: (# ByteCount, CRC, BufInx, indx: @Integer; Buffer: ^BufType; enter Buffer[] do (for i: Buffer.R.range repeat (Buffer.R[i] %Bxor (CRC %srl 24)) -> indx; (CRC %sll 8) %Bxor CRCTable[Indx+1] -> CRC; for); exit CRC #); (* Example use: *) theBuffer: @BufType; do InitCRCTable; (* Extend theBuffer to 117 elements: *) 117->theBuffer.R.extend; (* Put something in theBuffer: *) (for i: 117 repeat i->theBuffer.R[i]; for); 'The CRC32 is (zero, as no CRCtable has been loaded.) : '->screen.putText; theBuffer[]->GetCRC32->screen.putInt;screen.newLine; #) I think it does the same as your function, but I'm not quite sure, as I have been guessing the semantics of some of the operations (like "LongRec" and ".HI") ============= The following shifting primites exist, but they are not in the official language description yet, so they may still change: usage E1 OP E2 OP: %srl shift right logical of E1 by E2 bits %sll shift left logical of E1 by E2 bits %sra shift right arithemetic of E1 by E2 bits %sla shift left arithemetic of E1 by E2 bits %ror rotate right of E1 by E2 bits %rol rotate left of E1 by E2 bits %Band bitwise and %Bor bitwise or %Bxor bitwise exclusive or And a unary one: usage OP E1 OP: %Bnot bitwise not Regards, -- ** Morten Grouleff: ** ** Earthworm Jim PC: ** ** Mjølner Informatics: **