Average Values in 68000 Assembly
Write an MC68000 assembly language program that computes the average of fifteen data
bytes in memory
• Your program should expect to find the data bytes stored at memory locations$600 thru $60E. All values are positive and their sum may require more than 8bits.
• Your program should store the result as follows:
o Integral part of average at Byte $760
o Fractional part x 10 (the remainder after division) at Byte $761
• Start your executable instructions at $800
• Your executable instructions should not use numbers to specify any addresses.
Instead,
o Use ORG directives to set the location counter to the proper place,
o Use DS.B directives to define names for the data bytes, and
oSpecify the data address by name in the instructions.
Example: ORG $600
DATA1 DS.B 1
DATA2 DS.B 1
..
ORG $800
..
MOVE.B DATA1, D0
• End your program with TRAP #15 (D0 set to 9) and END
• Include global and local comments
• Run the program several times with different data. Be sure to set the PC for $800,
not $600
Solution
program.X68
*———————————————————–
* Title :
* Written by :
* Date :
* Description:
*———————————————————–
ORG $600
DATA1 DS.B 1
DATA2 DS.B 1
DATA3 DS.B 1
DATA4 DS.B 1
DATA5 DS.B 1
DATA6 DS.B 1
DATA7 DS.B 1
DATA8 DS.B 1
DATA9 DS.B 1
DATA10 DS.B 1
DATA11 DS.B 1
DATA12 DS.B 1
DATA13 DS.B 1
DATA14 DS.B 1
DATA15 DS.B 1
ORG $760
INTEG DS.B 1
FRACT DS.B 1
ORG $800
MOVE.L #0,D1 ; D1 will contain the sum, initialize to zero
MOVE.B DATA1, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA2, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA3, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA4, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA5, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA6, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA7, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA8, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA9, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA10, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA11, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA12, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA13, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA14, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
MOVE.B DATA15, D0 ; load value from array into D0
ADD.L D0,D1 ; add read data to D1
DIVU #15,D1 ; divide sum by 15 to get the average
MOVE.B D1,INTEG ; save quotient as integral part
SWAP D1 ; put the remainder in the low word of D1
MOVE.B D1,FRACT ; save remainder as fractional part
MOVE.L #9,D0 ; end program
TRAP #15
END
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~