# 68000 Code to Sum Values in a Range That are Multiples of a Value

Write an MC6800 program that adds up all numbers divisible by 11 between two limits,
e.g., from 15 to 400
• Your program must use at least one loop
• Your program should store the sum in memory location \$300; check the resultafter running the program
• Start your program at address \$400
• Include all necessary global and local comments
• For this program, you may not use numbers for any addresses except in an ORGdirective (use labels instead for other addresses)
• Be sure to run your program and check the results
• The name of your program should be your last name (or its first eight letters)
• Submit your program file (with extension .X68) along with representative resultsas paper copies in the class on or before the due date.

Solution

program.X68

*———————————————————–

* Title      :

* Written by :

* Date       :

* Description:

*———————————————————–

ORG    \$400

START:                  ; first instruction of program

LEA  FIRST,A0

MOVE.L  (A0),D1     ; read first limit in D1

LEA  LAST,A0

MOVE.L  (A0),D2     ; read last limit in D2

MOVE.L  #0,D3       ;  D3 will contain the sum, initialize to 0

MOVE.L  #16,D4      ;  D4 is always 16

LOOP:

MOVE.L D1,D0        ; put current number in D0 for division

DIVU #11,D0         ; divide by 11

LSR.L D4,D0         ; put the remainder at lower 16 bits by shifting to the right

CMP.W #0,D0         ; see if the remainder is zero

BNE NEXT            ; if not, is not divisible by 11, go to next

ADD.L D1,D3         ; if it’s divisible, add to the sum

NEXT:

ADD.L #1,D1         ; go to next number

CMP.L D2,D1         ; compare current number with upper limit

BLE   LOOP          ; continue while we don’t go above the upper limit

LEA  ADDR,A0

MOVE.L  (A0),A0     ; read address to save sum in A0

MOVE.L D3,(A0)      ; save sum in the result address

SIMHALT             ; halt simulator

FIRST:  DC.L  15        ; lower limit

LAST:   DC.L  400       ; upper limit

ADDR:   DC.L  \$300      ; address to save result

END    START        ; last line of source

*~Font name~Courier New~

*~Font size~10~

*~Tab type~1~

*~Tab size~4~