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: <599.UUL1.3#5129@willett.UUCP> Date: 2 Mar 90 03:56:39 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 70 Date: 03-01-90 (00:48) Number: 404 (Echo) To: ALL Refer#: NONE From: JACK BROWN Read: (N/A) Subj: FORTH SOLUTION TO 1C Status: PUBLIC MESSAGE ( 68hc11 Assembly Language Programming Course ) ( Problem 1c ) ( Write a 68HC11 assembly language program which will find the ) ( largest of 10 numbers stored in contiguous memory locations ) ( starting at location $0020. The numbers are single byte ) ( unsigned integers. Save the largest number in memory at ) ( location $002A. ) ( Solution 1c ) ( Since we have no free memory at $0020 we will use memory at $90 ) ( and location $9A for the largest number. ) ( Find the maximum of 10 bytes located at $90, max at $9A ) HEX 0090 CONSTANT DATA ( Location of byte array of data ) 009A CONSTANT MAXI ( Location to save maximum value ) 000A CONSTANT N ( Size of byte array ) DATA N 22 FILL ( Some test data ) 88 DATA 5 + C! ( 88 should end up at 9A ) 0 MAXI C! ( High Level Forth Solution : ) ( : MAXIMUM ( -- ) ( 0 10 0 DO DATA I + C@ 2DUP < ) ( IF SWAP THEN DROP ) ( LOOP MAXI C! ; ) ( Typical assembly language solution to the maximum problem ) CODE MAXIMUM ( -- ) CLRA, ( set maximum to zero ) N #, LDX, ( set byte array size in X ) BEGIN, DATA ,X CMPA, ( max - data ) U<, IF, DATA ,X LDAA, ( Save current as maximum ) THEN, DEX, ( Point to next item in byte array ) 0=, ( Continue until all have been checked ) UNTIL, MAXI DIR STAA, ( store maximum value ) NEXT END-CODE ( Extra Problem for the Forth Assemblers! ) ( Write a code definition and a high level definitions for the word ) ( MAX_BYTE that takes the address of a byte array and the byte count) ( on the stack and leaves the maximum value in the byte array on the) ( stack. MAX_BYTE ( adr n -- max ) ( Make sure that it works for both direct and extended page byte ) ( arrays. ) 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'