ECE243 Practice Question Website


Main Assembly Programming Input/Output Memory Computer Architecture Advanced Topics

Assembly Programming Questions





Question 15

Student information is being held in a data area, where each student record has the following format:
       The first nine bytes are the student number, held in ASCII
       The next byte is the course mark
       The next word is the section identifier

There are well over three hundred such student records that have been loaded sequentially into memory starting at address $10000. The last record loaded is a dummy record with a section identifier of $FFFF, to show the end of the records.

Write an assembler subroutine GetMax that will scan the entire list and find the highest mark. If there is a tie, the first student in the list with the highest mark should be found. The subroutine should return the starting address of this record in address register a3.

Hints

Think about Questions 12, 13, and 14.

Answer

	GetMax 	movea.l 	#$10000,a0 	;point a0 to records
		movea.l 	a0,a3 		;init return pointer
		clr.b 		d0 		;d0 holds the max mark
	Loop 	move.w 		$A(a0),d1 	;get section ID
		cmpi.w 		$FFFF,d1 	;see if done
		beq 		Exit 		;leave loop if so
		cmp.b 		9(a0),d0 	;see if max so far
		bge 		L1 		;br if not
		movea.l 	a0,a3 		;reset the pointer
		move.b 		9(a0),d0 	;set the new max so far
	L1 	adda.l 		#$C,a0 		;go to next record
		bra 		Loop 		;and look at that one
	Exit 	rts 				;done