Example on 68000 programming part 1

Example 10.1

Determine the effect of each of the following 68000 instructions:

  • CLR D0
  • MOVE. L D1, D0
  • CLR.L (A0) +
  • MOVE -(A0), D0
  • MOVE 20 (A0 ), D0
  • MOVEQ.L #$D7, D0
  • MOVE 21 (A0, Al.L), D0

Assume the following initial configuration before each instruction is executed; also assume all numbers in hex:

image

Example 10.2

Write a 68000 assembly language program that implements each of the following C language program segments:

imagewhere sum is the address of the 16-bit result of addition.

ii) Write a 68000 assembly language program to find (X2) I (3276510) where X is a 16-bit signed number stored in D0.W. Store the 32-bit result (quotient and remainder) onto the user stack.

iii) What are the remainder, quotient, and register containing them after execution of the following 68000 instruction sequence?

image

image

Note that, in the above condition Fin DBF is always false. Hence, the program exits from the LOOP when D I= -1. Therefore, the addition process is performed 10 times.

image

Example 10.3

Write a 68000 assembly program at address $002000 to clear l 0010 consecutive bytes (from low to high addresses) to zero starting at location $003000.

Solution

image

No warnings generated

Note that the 68000 has no HALT instruction .. Therefore, the unconditional jump to the same location such as FINISH JMP FINISH is normally used at the end of the program. Because DBF is a word instruction and considers D0’s low 16-bit word as the l00p count, one should be careful about initializing D0 using MOVEQ. L #d8, Dn since this instruction sign extends low byte of Dn to 32 bits.

Example 10.4

Write a 68000 assembly language program at address $001000 to compute image where

X1. and Yi are signed 16-bit numbers and N = 100. Store the 32-bit result in D 1. Assume that the starting addresses of X. and Yj are 10016 and 20016 respectively.

image

Example 10.5

Write a 68000 subroutine to compute Y = image. Assume the X.’s are 16-bit signed integers and N = 100. The numbers are stored in consecutive locations. Assume A0 points to the X/s and A7 is already initialized in the main program. Store 32-bit result in D1 (16-bit remainder in high word of Dl and 16-bit quotient in the low word of Dl). Assume user mode.

image

In the above program, DIVU is used for computing LXi2/N since both SUM (Xi**2) and N=I00 are unsigned (positive). Note that in order to execute the above program, values for must be stored in memory using assembler directive, DC.W.

Example 10.6

Write a 68000 assembly language program at address 0 to move a block of 16-bit data of length I 0010 from the source block starting at location 002000 16 to the destination block starting at location 003000 16 from low to high addresses.

Solution

image

Note: Typical assemblers assemble a program starting at address 0 if assembler directive ORG is not used at the beginning of the program.

Example 10.7

Write a 68000 assembly language program at address 0 to add two words, each containing two ASCII digits. The first word is stored in two consecutive locations (from LOW to HIGH) with the low byte pointed to by A0 at address 000300 16, and the second word is stored in two consecutive locations (from LOW to HIGH) with the low byte pointed to by AI at 000700 16• Store the packed BCD result in D5.

Solution

image

Leave a comment

Your email address will not be published. Required fields are marked *