Assignment 5:

Homework Assignment

Write an MC68000 program that will examine a list of test scores stored in memory.
Transfer any passing score (greater than or equal to 50) to a table in memory, and transfer
any failing score to another table in memory. Also, keep a count of the number of scores
in each table.
• Assume that twenty scores are stored in memory words starting at location $5000.
Define this table of words, and assign a label to it using the DS.W assembler
directive. (How do you force its location to $5000?)
• Store all passing scores in memory words starting at location $5100, and store all
failing scores starting at location $5200. Define these tables using DS.W
assembler directives.
• Store the final count for the number of passing scores in register D2 and the
number of failing scores in register D3.
• Start your program at location $800.
• Include all necessary global and local comments.
• Use numbers to represent addresses only in ORG directives; for other instructions,
use labels.
• Clear your tables of passing and failing scores using program instructions at the
start of your program, to prepare for repeat runs.
• Do not leave any blank words between scores in either table.
• Try your program several times, with different data
• The name of your program should be your last name or its first eight letters.
Submit your program file (with extension .X68) and representative results as a
hard copy in the class prior to the due date.

Solution for Assignment 5:

ORG    $800

START

LEA PASSING,A1      ; load address of passing scores into A1

LEA FAILING,A2      ; load address of failing scores into A2

MOVE #20,D1         ; we will use D1 as a counter for the 20 positions

FILL

MOVE.W  #0,(A1)     ; clear the current position in the passing table

MOVE.W  #0,(A2)     ; clear the current position in the failing table

ADD #2,A1           ; go to next position in the passing table

ADD #2,A2           ; go to next position in the failing table

SUB #1,D1           ; decrement position counter

BNE FILL            ; if it’s not zero, repeat

LEA SCORES,A0       ; load address of scores into A0

LEA PASSING,A1      ; load address of passing scores into A1

LEA FAILING,A2      ; load address of failing scores into A2

MOVE #0,D2          ; initialize number of passing scores to zero

MOVE #0,D3          ; initialize number of failing scores to zero

MOVE #20,D1         ; we will use D1 as a counter for the 20 scores

COUNT

MOVE.W (A0),D0      ; load a score from the array

CMP.W  #50,D0       ; compare with 50 to see if it’s a passing or failing score

BLT   FAIL          ; if it’s lower than 50 it’s failing

MOVE.W D0,(A1)      ; otherwise it’s a passing score, save it in the passing table

ADD  #2,A1          ; increment the pointer to the next empty space in the passing table

ADD  #1,D2          ; increment the number of passing scores

BRA  NEXT           ; go to next element by skipping the fail part

FAIL

MOVE.W D0,(A2)      ; it’s a failing score, save it in the failing table

ADD  #2,A2          ; increment the pointer to the next empty space in the failing table

ADD  #1,D3          ; increment the number of failing scores

NEXT

ADD #2,A0           ; go to next score in the table

SUB #1,D1           ; decrement score counter

BNE COUNT           ; if it’s not zero, repeat

MOVE.L #9,D0        ; end program

TRAP #15

ORG    $5000

SCORES   DS.W 20

ORG    $5100

PASSING   DS.W 20

ORG    $5200

FAILING   DS.W 20

END START

*~Font name~Courier New~

*~Font size~10~

*~Tab type~1~

*~Tab size~4~