Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: forth eng./68hc11 new micros Message-ID: <600.UUL1.3#5129@willett.UUCP> Date: 2 Mar 90 03:56:43 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 59 Date: 03-01-90 (00:51) Number: 405 (Echo) To: ALL Refer#: NONE From: JACK BROWN Read: (N/A) Subj: FORTH SOLUTION TO 1D Status: PUBLIC MESSAGE ( 68hc11 Assembly Language Programming Course ) ( Problem 1d ) ( Write a 68HC11 assembly language program which will calculate ) ( the average of four data values stored in locations $00 - $03 ) ( and store the result in location $04 ) ( We will perform the exercise at $90 - $93 and put result at $94 ) HEX 0090 CONSTANT DATA ( Data array of four values to average ) 0004 CONSTANT N ( Count of data values to average ) 0094 CONSTANT RESULT ( Average of four numbers ) ( High level Forth Solution : ) ( : AVERAGE ( -- ) ( 0 N 0 DO DATA I + C@ + LOOP N / RESULT C! ; ) ( Typical assembly language solution ) CODE AVERAGE ( -- ) N #, LDX, ( Load byte array size ) CLRA, ( Clear D to hold current byte ) CLRB, BEGIN, DATA 1- ,X ADDB, ( Accumulate total ) 0 #, ADCA, ( Sum = Sum + current byte ) DEX, ( Decrement byte counter ) 0=, ( Continue until done ) UNTIL, N #, LDX, IDIV, ( Compute average ) XGDX, RESULT DIR STAB, ( Save computed average ) NEXT END-CODE ( Extra problem for Forth assemblers: Write both a code definition ) ( and a high level Forth definition for a word called BYTE_AVG that ) ( takes as stack input parameters the address of a byte array and ) ( the byte array size and leaves as a stack output the average of ) ( the byte array: BYTE_AVG ( adr n -- average ) NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'