Upload
david-sanchez
View
41
Download
6
Tags:
Embed Size (px)
DESCRIPTION
Motorola 68000 assembly programs and examples.
Citation preview
Chapter 10, Example 10
Example 6.3Write a 68000 assembly program at address $002000 to clear 100 consecutive bytes to zero from LOW to HIGH addresses starting at location $003000.
Solution
ORG
$2000
; STARTING ADDRESS
MOVEA.L #$3000,A0; LOAD A0 WITH $3000
MOVE.W #99,D0
; MOVE 99 INTO D0
LOOP CLR.B (A0)+
; CLEAR[3000H]+
DBF.W D0,LOOP ; DECREMENT AND
; BRANCH
FINISH JMP FINISH
; HALT
Code Used:
ORG$3000
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
DC.B$01,$02,$03,$04,$05
DC.B$06,$07,$08,$09,$10
ORG$2000
MOVEA.L #$3000,A0
;Load A0 with $3000
MOVE.W #99,D0
;Move 99 into D0
LOOPCLR.B(A0)+
;Clear [3000] and point to next address
DBF.WD0,LOOP
;Decrement and branch
FINISHJMPFINISH
;HaltExample 6.4
Write a 68000 assembly language program at address $4000 to move a block of 16-bit data of length 10010 from the source block starting at location 00200016 to the destination block starting at location 00300016 from low to high addresses.
SolutionThe assembly language program is shown below:
ORG $4000
MOVEA.W #$2000,A4 ;LOAD A4 WITH SOURCE ADDR
MOVEA.W #$3000,A5 ;LOAD A5 WITH DEST ADDR
MOVE.W #99,D0 ;LOAD D0 WITH COUNT -1=99
START MOVE.W (A4)+,(A5)+;MOVE SOURCE DATA TO DEST
DBF.W D0,START ;BRANCH IF D0
STAY JMP STAY ;HALT
The above program is modified to move five 16-bit data as follows:
ORG $2000
DC.W $0100,$0200,$0300,$0400,$0500
ORG $4000
MOVEA.W #$2000,A4
MOVEA.W #$3000,A5
MOVE.W #4,D0
START MOVE.W (A4)+,(A5)+
DBF.W D0,START
STAY JMP STAY
EXAMPLE 6.8
Write a 68000 assembly language program at address $3000 to add two 64-bit numbers as follows:
[D0.L] [D1.L]
+ [D2.L] [D3.L]
-----------------------
[D2.L] [D3.L]Solution
ORG
$3000
ADD.LD1,D3 ; Add low 32 bits, store result in D3.L
ADDX.LD0,D2 ; Add with carry high 32 bits, store result
END JMP
END ; Halt
EXAMPLE 6.9Write a 68000 assembly language program at address $2000 to add four 32-bit numbers stored in consecutive locations from low to high addresses starting at address $3000. Store the 32-bit result onto the user stack. Assume that no carry is generated due to addition of two consecutive 32-bit numbers and A7 is already initialized.
Solution
ORG
$3000
DC.L 1,2,3,4
ORG $2000
MOVEQ.L #3,D0 ; Move 3 into D0
MOVEA.L #$3000,A0;Initialize A0
CLR.L D1 ; Clear sum to 0
START ADD.L (A0)+,D1 ; Add
DBF.W D0,START; perform loop
MOVE.LD1,-(A7) ; push result
FINISH JMP FINISH
Numerical ExampleAssume data as 1,2,3,4. The final result , $A (10 decimal) will be stored in D1.L.
Simulation ResultsThe following screen shot shows data , $00000001, $00000002, $00000003 and $00000004 in memory locations starting at address $3000. The data are circled, each 4 bytes long:
As the program is initializing values, the registers are being changed accordingly:
After the first number ($00000001) is added to the sum in D1.L during the first pass, register D1.L will contain the 32-bit SUM, $00000001 as follows:
The following screen shots show how all the numbers are added, and the 32-bit result ($0000000A) is pushed onto the user stack:
A7 was $00010000 and storing the result of the sum, D1, using predecrement addressing, A7 is FFFC and the data is pushed in to the stack. A7 is decremented by 4 because a long word is stored. D0.W = $FFFF indicating it is -1 to jump out of the loop. EXAMPLE 6.10
Write a 68000 assembly language program at address $2000 to add ten 32-bit numbers stored in consecutive locations starting at address $3000. Initialize A6 to $00200504 and use low 24 bits of A6 as the stack pointer to push the 32-bit result. Use only ADDX instruction for adding two 32-bit numbers each time through the loop. Assume that no carry is generated due to addition of two consecutive 32-bit numbers; this will provide the 32-bit result. This example illustrates use of the 68000 ADDX instruction.
SolutionThe assembly language program is shown below:
ORG $3000
DC.L 2,3,7,5,1,9,6,4,6,1
START_ADR EQU $3000
ORG $2000
COUNT EQU 9
MOVEA.L #START_ADR,A0 ; LOAD STARTING ADDRESS IN A0
MOVE.B #COUNT,D0
; USE D0 AS A COUNTER
MOVEA.L #$00200504,A6 ; USE A6 AS THE SP
CLR.L D1 ; CLEAR D1
ADDI.B #0,D6 ; CLEAR X BIT
AGAIN MOVE.L (A0)+,D3 ; MOVE A 32 BIT NUMBER IN D3
ADDX.L D3,D1 ;ADD NUMBERS USING ADDX
DBF.W D0,AGAIN ;REPEAT UNTIL D0 = -1 MOVE.L
D1,-(A6)
;PUSH 32-BIT RESULT ONTO STACK FINISH JMP FINISH
Example 6.11
Write a 68000 assembly program at address $2000 to multiply an 8-bit signed number in the low byte of D1 by a 16-bit signed number in the high word of D5. Store the result in D3. Assume the number is already stored in D1.B.
Solution
ORG
$2000
EXT.W
D1 ; SIGN EXTENDS LOW BYTE OF D1
SWAP.W D5 ; SWAP LOW WORD WITH HIGH WORD OF D5
MULS.W D1,D5 ; MULTIPLY D1 WITH D5, STORE RESULT
MOVE.L D5,D3 ; COPY RESULT IN D3
FINISH JMP FINISH
EXAMPLE 6.12
Write a 68000 assembly language program at address $2000 to compute XiYi, where Xi s and Yi ,s are signed 16-bit numbers and N = 100. Store the 32-bit result in D1. Assume that the starting addresses of Xi and Yi are 300016 and 400016 respectively.
SolutionThe assembly language program is provided below:P
EQU
$3000
Q
EQU
$4000
ORG
$2000
MOVE.W #99,D0 ;MOVE 99 INTO DO
LEA.L
P,A0 ;LOAD ADDRESS P INTO A0
LEA.L
Q,A1 ;LOAD ADDRESS Q INTO A1
CLR.L
D1 ;INITIALIZE D1 TO ZERO
LOOP
MOVE.W (A0)+,D2 ;MOVE [X] TO D2
MULS.W (A1)+,D2 ;D2