below The following program calculates the sum of the numbers stored in the LIST
ID: 1846443 • Letter: B
Question
below
The following program calculates the sum of the numbers stored in the LIST. Modify the above program such that it calculates the sum of even numbers (0+ 2 + 4 + 6 +8) and the sum of odd numbers (1 + 3 + 5 + 7 + 9) separately but in the same program. The program should store the sum of even numbers in D2 and the sum of odd numbers in D3. Use the location counter (*) to calculate the number of elements NUMLEN in the LIST and use NUMLEN to load the loop counter in line 2 (MOVE) of the program below. Hint: Notice that the SCORES are given as numbers 0 to 9 with even and odd numbers alternating. Starting from 0. if you skip one address you get to 2 and so on. Similarly, starting from 1 if you skip one address you get to 3 and so on. Modify the program written in Lab Exercise 2 above such that the program displays the sum of the even and numbers on the LEDs with three delays between the two displays. Use the subroutine DELAY from the pre-lab exercise. Write a program to flash all the LEDs at a rate of approx. 1 second. Use the subroutine DELAY from the pre-lab exercise to add a delay of approx. 1 second between the ON and OFF states of the LEDs. Write a program to control the 8 LEDs using the 8 switches on the Simulator. This can be done easily by reading the state of the switches (from address $E00012) and then outputting this value to the 8 LEDs (at address $E00010).Explanation / Answer
2)
ORG $1000
START LEA LIST,A0 ;
MOVE.B NUMLEN,D0 ; Load D0 wiht the size of List
CLR.B D2 ;
CLR.B D3 ;
Loop ADD.B (A0),D2 ; Add number from A0 ie even to D2
ADD.L #1,A0 ; increment A0
ADD.B (A0),D2 ; Add number from A0 ie odd to D3
ADD.L #1,A0 ; increment A0
SUB.B #1,D0 ;
BNE Loop ;
MOVE.B #9,D0 ;
TRAP #15 ;
List DC.B 0,1,2,3,4,5,6,7,8,9
NUMLEN EQU *-List ; Load NUMLEN with the size of List * is current location counter.
3)
ORG $1000
START LEA LIST,A0 ;
MOVE.B NUMLEN,D0 ; Load D0 wiht the size of List
CLR.B D2 ;
CLR.B D3 ;
Loop ADD.B (A0),D2 ; Add number from A0 ie even to D2
ADD.L #1,A0 ; increment A0
ADD.B (A0),D2 ; Add number from A0 ie odd to D3
ADD.L #1,A0 ; increment A0
SUB.B #1,D0 ;
BNE Loop ;
MOVE.B #9,D0 ;
Forever MOV.B D2,(LED) ; Load the LED with the value in Even sum
DELAY
DELAY
DELAY
MOV.B D3,(LED) ; Load the LED with the value in Even sum
DELAY
DELAY
DELAY
BRA Forever ; Loop back for continuous display
List DC.B 0,1,2,3,4,5,6,7,8,9
NUMLEN EQU *-List ; Load NUMLEN with the size of List * is current location counter.
LED EQU E00010 ; Address of the LED
4)
ORG $1000
Forever MOV.B #0xFF,(LED) ; Load the LED with 0xFF all the LED are ON
DELAY
MOV.B #0,(LED) ; Load the LED with 0 all the LED are Off
DELAY
BRA Forever ; Loop back for continuous display
LED EQU E00010 ; Address of the LED
5)
ORG $1000
Forever MOV.B (SWITCH),D0 ; Read the value on switch
MOV.B D0,(LED) ; Load the LED with the read value
BRA Forever ; Loop back for continuous display
LED EQU E00010 ; Address of the LED
SWITCH EQU E00012 ; Address of the Switch
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.