Sign in to follow this  
kev670

assembly program help

Recommended Posts

I'm trying to design an assembly program that does 3 things. first a user created array is input. then the values are put into a new array which lines them up smallest number first. (this is where I'm stuck. after this they are put into a third array where the numbers are reversed, so biggest numbers come first then a smaller then number and then the smallest. finally the factorial is calculated and put into a 4th array. any help you could give me would be much appreciated. I'm using wism68 as a simulator for the 68000 processor. i know that this may be the wrong forum to ask so if someone could point me in the direction of a better place that would be great to
PROGRAM	EQU $6000
DATA	EQU $4000

		ORG PROGRAM

		LEA ASCSORT,A1		;GET START ADDRESS OF ARRAY
		LEA DESCSORT,A2		;GET START ADDRESS OF ARRAY
		LEA FACTS,A3		;GET START ADDRESS OF ARRAY

		NOP			;N O P = COMMENT OUTERWHILE LOOP STARTS HERE => USE CMP, SOME FORM OF BRA AND COUNTER
		LEA INPUT,A0		;GET START ADDRESS OF ARRAY


		NOP			;INNER WHILE LOOP

W2		MOVE #0,D1		;INTIALISE D1 TO TERMINATING VALUE
		MOVE.B (A0),D0		;ASSUME THE FIRST ELEMENT IS SMALLEST

W1		CMP.B #8,D1		;COMPARE ELEMENT (A0) TO D1
		BEQ EXIT		;BRANCH TO EXIT IF EQUAL
		ADD #1,D1		;INCREMENT LOOP COUNTER

		CMP.B #$F,(A0)		;CHECK IF ARRAY ELEMENT = PREVIOUSLY FOUND ELEMENT
		BEQ NEXT		;IF IT IS, PROGRESS TO NEXT ELEMENT

		CMP.B (A0),D0		;IF NOT COMPARE WITH CURRENT SMALLEST
		BLT NEXT		;IF NOT LESS THAN THEN BRACH TO NEXT

		MOVE.B (A0),D0		;OTHERWISE MOVE NEW SMALLER VALUE TO D0
		MOVEA A0,A5		;USE A5 TO TEMPORARILY HOLD ADDRESS OF MIN VALUE

NEXT	ADDA #1,A0
		BRA W1			;GO BACK TO START OF WHILE LOOP

EXIT:	MOVE.B D0,(A1)
		MOVE.B #$F,(A5)		;OVERWRITE LOCATION WHERE MIN VALUE FOUND USING $F AS A MASK


		NOP			;END OF OUTER WHILE LOOP
		
		JMP W2

		STOP #$2700


	ORG DATA
INPUT 	DC.B 4,3,2,5,1,6,3,8
ASCSORT	DS.B 8
DESCSORT DS.B 8
FACTS	DS.L 8

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this